GuobaGuoba Utils

useSyncState

@guoba-ai/hook / useSyncState

Function: useSyncState()

function useSyncState<T>(prop, comparator?): [T, Dispatch<SetStateAction<T>>];

Defined in: useSyncState.ts:18

A custom React hook that synchronizes the state with the prop.

Type Parameters

T

T

The type of the prop.

Parameters

prop

T

The prop to synchronize with the state.

comparator?

(pre, cur) => boolean

Compare current and previous prop value, return true if they are identical.

Returns

[T, Dispatch<SetStateAction<T>>]

A state variable, and a function to update it.

Example

const [state, setState] = useSyncState(initialProp);

On this page