history-adapter
v2.1.1
Published
A "history adapter" for managing undoable (and redoable) state changes.
Downloads
16
Maintainers
Readme
History Adapter
A "history adapter" for managing undoable (and redoable) state changes with immer, which pairs well with state management solutions like Redux and Zustand.
Includes generic methods along with Redux-specific helpers.
import { createHistoryAdapter } from "history-adapter/redux";
import { createSlice } from "@reduxjs/toolkit";
interface CounterState {
value: number;
}
const counterAdapter = createHistoryAdapter<CounterState>({ limit: 10 });
const counterSlice = createSlice({
name: "counter",
initialState: { value: 0 },
reducers: {
undo: counterAdapter.undo,
redo: counterAdapter.redo,
increment: counterAdapter.undoableReducer((state) => {
state.value += 1;
}),
},
});
See website for more information.