sisense.com
✅ You are viewing documentation for the latest version of Compose SDK.
Version:

Function useSyncedState Beta

useSyncedState<T>(syncValue, options = {}): [T, Dispatch< SetStateAction< T > >]

A custom React hook that behaves like the regular useState, but also synchronizes the state with an external syncValue.

Type parameters

Parameter
T

Parameters

ParameterTypeDescription
syncValueTThe external value to synchronize with. When this value changes (as
determined by syncCompareFn), the local state is updated to match it.
optionsUseSyncedStateOptions< T >Optional configuration object. See UseSyncedStateOptions for the
onLocalStateChange and syncCompareFn fields.

Returns

[T, Dispatch< SetStateAction< T > >]

A tuple of [localState, setState] — the current local state and a setter that both updates state and fires onLocalStateChange.

Example

const [localState, setLocalState] = useSyncedState(externalValue, {
  onLocalStateChange: (s) => console.log('local update', s),
});
Last Updated: