, .
npm deep-equal contentState (.. contentState JS convertToRaw).
onChange contentState.
Note. Comparison using a module with a deep value is about 5 times faster than wrapping node assert.deepEqual () in try / catch.
Here is the onChange handler code:
const deepEqual = require('deep-equal');
this.onChange = (editorState) => {
let oldContent = convertToRaw(this.state.editorState.getCurrentContent());
let newContent = convertToRaw(editorState.getCurrentContent());
let sameContent = deepEqual(oldContent, newContent);
this.setState({editorState});
if (sameContent === false)
console.log('Content has changed.');
}
source
share