Put it all together
Big apps keep their data in a store: one place holding the state, changed only by actions, telling anyone interested when it changes. You'll build one in about 25 lines, using closures, pure reducers, Sets and immutability — with undo for free.
The shape
const store = createStore(reducer, initialState);
const stop = store.subscribe((state) => render(state));
store.dispatch({ type: "add", item: "momo" });
store.getState();
store.undo();
stop();