sharedStateFor<T> method

ValueState<T> sharedStateFor<T>({
  1. required Key key,
  2. StateMode mode = .watch,
})

Retrieves existing shared state by type and key within the same StateScope. Throws a StateError if no matching shared state is registered.

Implementation

ValueState<T> sharedStateFor<T>({
  required Key key,
  StateMode mode = .watch,
}) {
  return sharedStateOf<T>(
    () => throw StateError('No shared state registered for type $T and key $key.'),
    key: key,
    mode: mode,
  );
}