Function Pairs for Undo/Redo: Lighter Than Snapshots in Zustand and React Query
Snapshots sounded perfect for undo/redo—until React Query's caching made them a bloated mess. Here's the smarter fix: store undo/redo functions, not states, for a history stack that actually scales.
⚡ Key Takeaways
- Function pairs store undo/redo ops instead of full snapshots, slashing memory in Zustand + React Query stacks 𝕏
- Auto-wrapping mutations with runWithSnapshotUndo generates history effortlessly, with no-op guards 𝕏
- Grouping via groupId treats multi-step user actions (like drags) as atomic undos, mimicking real expectations 𝕏
Worth sharing?
Get the best Developer Tools stories of the week in your inbox — no noise, no spam.
Originally reported by dev.to