Slapbox Slapbox - 11 months ago 75
Javascript Question

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?

Answer Source

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.