Skip to main content

Function: useSharedState()

function useSharedState<T>(
key,
initial,
options?): [T, (next) => void];

Like useState, but the value exists in every tab, window, and worker on this origin. Late-joining tabs hydrate to the current value; concurrent writes converge last-writer-wins. Pass options.scope to delimit how much is shared ('everywhere' | 'tabs' | 'tab').

Type Parameters

Type Parameter
T

Parameters

ParameterType
keystring
initialT
options?UseSharedStateOptions

Returns

[T, (next) => void]