useStateXValue()

Returns the value of the given Path, StateX or Selector state.

This hook will implicitly subscribe the component to the given state.

This is the recommended hook to use when a component intends to read state without writing to it. atoms are writeable state while selectors may be either read-only or writeable. See selector() for more info.

The parameter options used in useStateX() are applicable for useStateXValue() as well.

Default Value Demo

If the state at a specific node is not set, it will be updated with the default value as shown below.

Demo

If the state exists, then the default value will be ignored. The default value also helps in inferring the state type.