Skip to content

Instantly share code, notes, and snippets.

View screfy's full-sized avatar
:electron:
screfy.com

screfy screfy

:electron:
screfy.com
View GitHub Profile
@KristofferEriksson
KristofferEriksson / useUndo.ts
Created January 31, 2024 11:34
A React hook that enhances your components with powerful undo/redo functionality
import { useCallback, useEffect, useRef, useState } from "react";
interface UseUndoHook<T> {
value: T;
onChange: (newValue: T) => void;
undo: () => void;
redo: () => void;
clear: () => void;
canUndo: boolean;
canRedo: boolean;