Skip to content

EskiMojo14/history-adapter

Repository files navigation

History Adapter

logo

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.