Skip to main content

useSimpleStateValueWithReactiveSelector

Caution: Unstable API

The accepted parameters, return value and behavior of this function may change, and it might be renamed or entirely removed between minor versions in future releases.

This is provided as an escape hatch in special cases where useSimpleStateValue is not behaving as expected. For example, the selector depends on external values (props or data from other hooks) and the returned value does not change when those dependencies change. Under normal circumstances, the returned value will change when those external values change and this hook is not needed.

Overview

Type: Function

React hook to consume a SimpleStateManager with a selector that is wrapped in useCallback.

const selector = useCallback((state) => { ... }, [])
const state = useStateValueWithReactiveSelector(stateManager, selector)
const selector = useCallback((state) => { ... }, [])
const state = useStateValueWithReactiveSelector(stateManager, selector, active)

Parameters

  • stateManagerThe State Manager to watch for changes.
    Type: SimpleStateManager
    Required: Yes
  • selectorA function that accepts the state as an argument and returns a derived value. This function must be declared outside of the component function body or wrapped in useCallback.
    Type: StateSelector
    Required: Yes
  • activeControls whether the hook should watch for state changes and trigger component update.
    Type: boolean
    Required: No — (default value: true)

Examples

Basic

Conditionally watch for changes