History Plugin
This is a plugin for the draft-js-plugins-editor
.
This plugin adds undo/redo functionality to your editor!
Usage
First instantiate the plugin:
import createUndoPlugin from 'draft-js-undo-plugin';
const undoPlugin = createUndoPlugin();
Now get the UndoButton
and the RedoButton
components from the instance:
const { UndoButton, RedoButton } = undoPlugin;
Which take two props, onChange
(a function that takes a new editor state as an argument and updates your editor's state) and editorState
(the current editor state). Render them with those props and your editor now has undo/redo functionality!
<UndoButton onChange={ this.onChange } editorState={ this.state.editorState } />
<RedoButton onChange={ this.onChange } editorState={ this.state.editorState } />