Function: useUndoableStateOptional()
useUndoableStateOptional<
T>(initial,options?): [T,UndoableSetter<T>,UndoableReset<T>]
Defined in: use-undoable-state.ts:176
Provider-optional variant of useUndoableState for reusable
components that may render with or without an AmnesiaProvider ancestor.
- With a provider: identical to
useUndoableState— every setter call pushes a reversible command onto the pinned scope, andresetclears that scope's history. - Without a provider: degrades to plain
useStatesemantics. Nothing throws, no history is recorded, andresetsimply overwrites the value.
The equals bail-out applies in both modes, and like useUndoableState
the hook pins to options.scopeId (default "default") — it never
floats to the active claim.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
initial | T | (() => T) |
options | UseUndoableStateOptions<T> |
Returns
[T, UndoableSetter<T>, UndoableReset<T>]
Example
// Inside a component library that cannot assume amnesia is installed:
const [title, setTitle, resetTitle] = useUndoableStateOptional("Untitled", {
label: "Edit title",
coalesceKey: "edit:title",
});