Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best performance method to check if contentState changed in DraftJS, or just editorState

I'm trying to have a function run only when the contentState itself has changed, not just the editorState.

My idea right now would be to store the old contentState as a string and compare it to the new contentState as a string, but this seems awfully wasteful to be converting states to strings and comparing them. Is there a better way?

like image 460
Slbox Avatar asked Aug 27 '16 15:08

Slbox


1 Answers

you can simply compare the value of your old state and the value of your new state you don't have to convert it to string.

EDIT: and here is a concept about react state that you don't have worry about a large state object as best practices recommend to do that way

Common misconception: state is held in a large object. It’s just object referencing a few other objects. Nothing large about it.

like image 123
Md.Estiak Ahmmed Avatar answered Oct 04 '22 05:10

Md.Estiak Ahmmed