useStateHistory

A React Hook that track and manipulate the history of a state automatically.

Demo

Source
{"hash":"ABCDEF","count":0}
/
{"snapshot":{"hash":"ABCDEF","count":0},"timestamp":1726045645669}
9/11/2024, 9:07:25 AM {"hash":"ABCDEF","count":0}

Usage

See API for more details.

Source

Click links below to view source on GitHub.

API

Almost the same as useManualStateHistory, but with an additional Pausable instance return.

Retuerns contain Pausable instance that can be paused, resumed.

See Pausable for more details.

const { ...history, ...pausable } = useStateHistory(state, options)

State

Same as useManualStateHistory#state.

Options

export interface UseStateHistoryOptions<Raw, Serialized = Raw> extends UseManualStateHistoryOptions<Raw, Serialized> { deep?: boolean }