Unable to get previous state in onChange plugin
See original GitHub issueI would like to create a plugin to save the editor content when onChange is fired. Following documentation, I would like to check previous document value before saving to database with:
if (prevValue.document !== newValue.document) {
// Save to database
}
But I can’t find a way to get my previous value from the onChange plugin handler:
const SavePlugin = () => ({
onChange: ({ value: newValue }, next) => {
// How can I get previousValue ??
if (prevValue.document !== newValue.document) {
const content = JSON.stringify(newValue.toJSON());
localStorage.setItem('content', content);
}
next();
},
});
Is there a way to get the previous state value from the onChange plugin event handler?
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
React state clearing onChange [duplicate] - Stack Overflow
React setState functions are asynchronous in nature so the console.log showing previous values might be due to the fact that the state ......
Read more >onChange doesn't fire if input re-renders due to a setState() in ...
I have a separate use case reproducing the same issue, since react makes batch updates to state once per event handler so if...
Read more >react-phone-number-input - npm
For example, if a user chooses "United States" and enters (213) 373-4253 in the input field then onChange(value) will be called with value...
Read more >jQuery API Documentation
A factory function that returns a chainable utility object with methods to register multiple callbacks into callback queues, invoke callback queues, and relay ......
Read more >The React Handbook – Learn React for Beginners
If you already have a React app installed using an older version of React, ... We can't assign a different literal to the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think this is a question better suited for the Slack channel (https://slate-slack.herokuapp.com/).
But you could, say, leverage the closure of the
SavePlugin
like so:You can close the issue (y)