Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add support for setting content state outside of an event listener

See original GitHub issue

Issue Description

I have a modal that have a list of text options with a copy button beside each. When you click the copy button it should take that takes and updates content which would render CKEditor with the correct content copied over showing. I have it wired up where onClick of the copy button updates editor content state, which works, but it doesn’t update what the editor shows in the UI since it seems it only updates via one of the set eventListeners.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

codeslayer1commented, Nov 18, 2017


Events are used for listening to changes that happen inside CKEditor and take actions based on that. You cannot use it the other way to perform action on CKeditor instance from outside.

To change content inside your CKEditor from your parent component(modal in your case). You need to add a ref to it and then access the child functions. Here is an example.

  1. Add ref like this to your CKEditor. <CKEditor ref={instance => { this.ckeditor = instance; }} />

  2. Now you can set data in your CKEditor like this. Simply call this method in your onClick of the copy button with new data. It will be reflected in your CKEditor. this.ckeditor.editorInstance.setData(yourData);

Hope this solves your query.

ramkrishna757575commented, Jan 4, 2018

Sure will try that. Thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

EventTarget.addEventListener() - Web APIs | MDN
It works on any event target, not just HTML or SVG elements. The method addEventListener() works by adding a function, or an object...
Read more >
Wrong React hooks behaviour with event listener
Another solution is to re-register the event listener every time, so a callback always ... useState currently supports only immutable state.
Read more >
Event handler in addEventListener doesn't have access to the ...
I'm using react 16.8.0-alpha.1 with hooks and typescript and noticed this strange behavior. If I attach an event listener to the document or ......
Read more >
How To Handle DOM and Window Events with React
In React apps, you can use event handlers to update state data, trigger prop changes, or prevent default browser actions. To do this,...
Read more >
Working with App State and Event Listeners in React Native
Firstly visiting useRef , we can give event listeners a true state value by making a couple of small changes from the above...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found