Skip to content

Hook useHistory() ​

useHistory<Type>(initialState: Type): { history: Type[]; stateIndex: number; pushState: (state: Type) => void; undo: () => void; redo: () => void; undoAvailable: boolean; redoAvailable: boolean; }

Source: history.ts

Returns an object that handles stateful history with undo and redo methods.

Type Parameters ​

Type ​

Type

Parameters ​

initialState ​

Type

Returns ​

history ​

history: Type[]

The entries of the history.

stateIndex ​

stateIndex: number

The index of the active entry in list of entries.

pushState ​

pushState: (state: Type) => void

Adds a new entry to the history.

Parameters ​

state ​

Type

Returns ​

void

undo ​

undo: () => void

Moves backwards in the history.

Returns ​

void

redo ​

redo: () => void

Moves forwards in the history.

Returns ​

void

undoAvailable ​

undoAvailable: boolean

redoAvailable ​

redoAvailable: boolean

Built by Prozilla