State Management · Senior · Question 59 of 75
What is an efficient way to implement undo/redo for a large document state?
- ✓Correct answer: Record changes as patches/inverse patches (e.g. Immer patches) or keep a bounded history of immutable snapshots
- 2Deep-clone the whole state into an array on every keystroke without limits
- 3Store only the last state and recompute from the server
Explanation
Structural sharing makes snapshots cheap, and patches are compact enough to sync or persist. Cap the history and group rapid changes into one step.