Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Draft.js with Reagent

Does anyone have any luck adapting Draft.js for Reagent? There's pretty heavy editing issues if Draft.js is imported right away via reagent/adapt-react-class. Cursor jumps, disappearing symbols when you're typing, onChange calls with incorrect EditorState, you name it.

People are reporting problems like this in clojurians/reagent Slack channel, but it seems there's no solution so far.

Any help would be greatly appreciated.

like image 540
ai212983 Avatar asked Nov 27 '25 13:11

ai212983


1 Answers

Okay, thanks to tonsky, I got the answer. Reagent/Rum are using deferred rendering with requestAnimationFrame, but Draft.Editor should be re-rendered immediately when editorState is set.

All we need is to call forceUpdate for editor parent component whenever editor onChange is invoked:

:editorState @editor-state-atom
:onChange    (fn [new-state]
               (reset! editor-state-atom new-state)
               (.forceUpdate @wrapper-state))

Code example is for Reagent, solution for Rum is identical

like image 188
ai212983 Avatar answered Nov 30 '25 06:11

ai212983



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!