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":1731400799680}
11/12/2024, 8:39:59 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 }