Skip to Content
⭐️ Leave a star →
HooksuseUndoRedo

useUndoRedo

A state container that keeps a bounded history of past and future values. Calling set clears the redo stack — standard text-editor behaviour.

import { useUndoRedo } from '@wire-ui/react' function TextEditor() { const { value, set, undo, redo, canUndo, canRedo } = useUndoRedo('', { limit: 100 }) return ( <> <textarea value={value} onChange={(e) => set(e.target.value)} /> <button onClick={undo} disabled={!canUndo}>Undo</button> <button onClick={redo} disabled={!canRedo}>Redo</button> </> ) }

Parameters

ParamTypeDescription
initialValueTStarting value.
options{ limit?: number }Max past entries retained. Defaults to 100. Pass Infinity for unbounded history.

Returns

KeyTypeDescription
valueTCurrent value.
set(next: T | ((prev: T) => T)) => voidPush a new value; clears the redo stack.
undo() => voidStep back. No-op if there is nothing to undo.
redo() => voidStep forward. No-op if there is nothing to redo.
reset(next?: T) => voidClear history and replace the current value (defaults to the initial).
clear() => voidClear history but keep the current value.
canUndobooleantrue if the past stack is non-empty.
canRedobooleantrue if the future stack is non-empty.
pastSizenumberSize of the undo stack.
futureSizenumberSize of the redo stack.
Last updated on

MIT License © 2026 wire-ui

useUndoRedo – Wire UI