codeslayer1 / react-ckeditor

CKEditor component for React with plugin and custom event listeners support
MIT License
129 stars 34 forks source link

Take an onLoad param or avoid local state to solve race condition #3

Closed ofirgeller closed 7 years ago

ofirgeller commented 7 years ago

When both the script and the default content are loaded async there is no sure why to set the correct content.

If content is loaded before script: Component renders and mounts. user can't pass the default content since It is not loaded yet Component copies empty content from props to state Content loads, user pass a new value as the content props, but this has no effect ckeditor is not ready so the user can't setData Script loads, setting the content to the default value that is not the real content because it is getting the content from the component state not from the prop that now is set to the content that was loaded

A way to solve this is to be able to pass a callback function to be called when the script has loaded.

Another way (better I think) would be to not have state at all in this component, and use the props directly, this way if the default content gets updated between the component mount and the script loading you are going to be setting the correct content.

codeslayer1 commented 7 years ago

I also think the second method would be better since even if I pass a callback function after scriptLoad, the user will have to again change props in that callback function which should be ideally taken care of by the library itself, without relying on the end user.

Will take this up soon.

codeslayer1 commented 7 years ago

This has been fixed. You can update to the latest version ^1.0.4 from Npm.