Hooks
There are a few hooks you can use in your functional components.
#
useMountedLogicAssure that the logic is mounted when the component renders and is unmounted when the component is destroyed.
This hook is not needed if you use any of the other hooks.
#
useActionsAssure the logic is mounted and fetch actions from the logic. Actions are automatically connected
to dispatch
.
#
useValuesAssure the logic is mounted and fetch values from it.
note
You can only use useValues
with destructoring
This is because internally useValues
uses getter functions
that call react-redux's useSelector
hooks when a value is accessed. Because hooks need to always be called in the same order,
you can't just store the object returned from useValues
and then use its properties later in
the code. Doing so might call the internal hooks in an unspecified order. Use useAllValues
if you
need to do this.
#
useAllValuesSimilar to useValues
, but selects all the values in the logic and stores their current state in an object.