Setup
A "history adapter" for managing undoable (and redoable) state changes with immer, which pairs well with state management solutions like Redux and Zustand.
Also includes a Redux specific version, with additional utilities for use with Redux Toolkit.
Sandboxes
Redux Toolkit
Zustand
Installation
Install with your package manager of choice:
- npm
- yarn
- bun
npm install history-adapter
yarn add history-adapter
bun add history-adapter
Usage
The main export of history-adapter
is the createHistoryAdapter
function. This function takes an optional configuration object and returns an object with useful methods for managing undoable state changes.
For a list of all available methods, see the API reference.
By default, history entries will be a copy of state before/after each change. However, you can use createPatchHistoryAdapter
to store JSON Patches instead.
Configuration
The createHistoryAdapter
function accepts an optional configuration object with some of the following properties:
limit
(number): The maximum number of history entries to store.- If not provided, all history entries will be stored.