Slate.js has some wonderful undo/redo history under the hood, by way of the
React hook useMemo
. Out of the box is works great, but if you want to reset
your editor back to an empty state (in scenarios where the component is
persistent on the page), the undo/redo history will still be available.
Because I wanted to completely reset the editor as if it was the user’s first
time interacting with it, I had to figure out how to clear out the history.
While I wasn’t able to find a built in command for it, I did figure out that you
can simply reset the history
object right on the editor. Said object houses
two arrays, one for undos
and one for redos
.
To reset the history of your editor, simple run:
editor.history = {
redos: [],
undos: [],
Now the editor won’t have any baggage the next time it’s used!