🌐 Frontend & Web

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.

Undo/redo history stack diagram using function pairs in Zustand and React Query

⚡ 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 𝕏
Published by

theAIcatchup

Ship faster. Build smarter.

Worth sharing?

Get the best Developer Tools stories of the week in your inbox — no noise, no spam.

Originally reported by dev.to

Stay in the loop

The week's most important stories from theAIcatchup, delivered once a week.