stateFor<T> method

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

Retrieves existing state owned by this element by type and key. Throws a StateError if no matching state is registered.

Implementation

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