Generic Undo Manager for React - Part 1
It’s probably my third day writing here. I’m not trying to keep a daily streak, but I get genuinely excited when I come across good code, so I end up wanting to share it right away. Some background...

Source: DEV Community
It’s probably my third day writing here. I’m not trying to keep a daily streak, but I get genuinely excited when I come across good code, so I end up wanting to share it right away. 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. I’m glad to say I found two solid approaches. You can probably guess that from the title since this is Part 1 😄 In this part, I’ll walk through one approach that I found really elegant—the one recommended by Redux. The idea The core idea is simple. Instead of just storing your current state, you store a bit of history along with it. { past: Array<T>, present: T, future: Array<T> } past → everything that came before present → your current state future → everything you’ve undone Undo and redo then become operations where y