Skip to content

Instantly share code, notes, and snippets.

View X-Y's full-sized avatar

Xun Yang X-Y

  • Stockholm, Sweden
View GitHub Profile
@X-Y
X-Y / useUndoReducer.ts
Last active November 3, 2022 13:52 — forked from johanquiroga/useUndoReducer.js
Undo/Redo capability for any reducer using react hook `useReducer`
import { useReducer, Dispatch } from "react";
export enum USE_UNDO_REDUCER_TYPES {
undo = "UNDO",
redo = "REDO",
}
export type UndoRedoAction = {
type: USE_UNDO_REDUCER_TYPES;
};
export type HistoryType<T> = {