Simple Undo/redo component and hook for react-final-form
https://nosovsh.github.io/react-final-form-undo/
npm install react react-dom react-final-form final-form
npm install react-final-form-undo
import {Undo} from "react-final-form-undo";
// Then inside your form
<Undo>
{({canUndo, canRedo, undo, redo}) => (
<>
<button
onClick={undo}
disabled={!canUndo}
>
Undo
</button>
<button
onClick={redo}
disabled={!canRedo}
>
Redo
</button>
</>
)}
</Undo>
import {useUndo} from "react-final-form-undo";
// Then inside your form
const {canUndo, canRedo, undo, redo} = useUndo();
// Then inside render
<>
<button
onClick={undo}
disabled={!canUndo}
>
Undo
</button>
<button
onClick={redo}
disabled={!canRedo}
>
Redo
</button>
</>
initialValues
for react-final-form should be provided and should be notundefined
- Undo stack is cleared when initial values are changed. So if you want your undo stack to be cleared after form save - set initial values to a new values. See example.
- implement tests
- fix known bug that undo stack is not cleared when you roll back to the beginning and then submit form
- clear undo stack after
reset
andinitialize
methods call