This hook calls selector with the Store's RootState and returns the
derived value. Then it watches the store,
calling the selector again for every change to the RootState. If the
value returned by selector is not identical to the last saved value, a
re-render will be triggered (and this hook will return the new value).
This hook recomputes its state when the selector changes. You should avoid
unnecessarily creating a new selector on every render. Selectors can usually
be created outside the component to avoid this. If your selector has some
prop dependencies, then wrap the selector in a React
useCallback to ensure the
reference stays the same as much as possible.
If your selector constructs a new data structure based on the RootState,
(rather than just selecting some part of the RootState or calculating a
primitive value), then it might return a non-identical value even when
nothing has changed. This is now prevented because we add a memoizing wrapper
to your selector. If state arguments remain the same, we will use the
previous value returned without executing your selector.
A hook for tracking a subpart or a computed value derived from the @watchable/store!RootState of a @watchable/store!Store by a @watchable/store!Selector function.
This hook calls
selector
with theStore
'sRootState
and returns the derived value. Then it watches the store, calling theselector
again for every change to theRootState
. If the value returned byselector
is not identical to the last saved value, a re-render will be triggered (and this hook will return the new value).This hook recomputes its state when the
selector
changes. You should avoid unnecessarily creating a new selector on every render. Selectors can usually be created outside the component to avoid this. If your selector has some prop dependencies, then wrap the selector in a React useCallback to ensure the reference stays the same as much as possible.If your
selector
constructs a new data structure based on theRootState
, (rather than just selecting some part of theRootState
or calculating a primitive value), then it might return a non-identical value even when nothing has changed. This is now prevented because we add a memoizing wrapper to your selector. If state arguments remain the same, we will use the previous value returned without executing your selector.See @watchable/store!Selector