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":1733472431809}
12/6/2024, 8:07:11 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 }