Using React Tracked with React Redux
The primary use case of React Tracked is to replace a use case of React Context. This is done by using use-context-selector
internally.
React Tracked exposes a low-level function called createTrackedSelector
to cover non-React Context use cases. It takes a hook called useSelector
and returns a hook called useTrackedState
:
const useTrackedState = createTrackedSelector(useSelector);
useSelector
is a hook that takes a selector function and returns the result of the selector function. It will trigger re-renders when the result changes. useTrackedState
is a hook that returns an entire state wrapped in proxies to track the state
usage.
Let's look at a concrete example with React Redux. This provides a useSelector
hook, and it's straightforward to apply createTrackedSelector
.
Important Note about React Redux
React Redux uses React Context internally, but it doesn't use Context for propagating a state value. It uses React...