
Time Travel for Your State: Undo/Redo - with Zustand and React Query (Part 2)
In Part 1, we discussed the snapshot pattern with past/present/future arrays for undo and redo. If you haven't checked it out, you can do so here . Some background In a personal project I've been working on, I spent the past week trying to find a clean, generic way to implement undo/redo without ending up with a bunch of hardcoded states. I wanted something that could manage itself instead of turning into a mess over time. The first approach with past , present , and future arrays? Elegant. Clean. But as I tried integrating it into my actual project, I started running into something that felt off. I'm using Zustand for client-side state and Tanstack Query for server state. React Query helps me make fewer network calls by caching data, so persisting full snapshots for every undo step started feeling heavy and redundant. The last approach still works great in many setups (especially Redux-like flows), but in my current stack it meant extra bookkeeping in Zustand just to track history tha
Continue reading on Dev.to
Opens in a new tab



