Api - @statek/react
view
Returns reactive version of provided component. Returned component has exactly the same props as provided one
useStore
Creates 'local' version of the store that is memoized between renders.
useSelected
Watches stores or selectors using provided callback and re-renders only when returned value changes.
Let's say we have store with todo list and info about which todo is currently opened
useUpdateOnAnyChange
Will re-render component every time any value of provided store changes
This hook is useful if we need to provide store value into 3rd party component we cannot wrap with view
useStatefulWatch
Allows creating watch effect that can have some internal 'state' in form of variables
Sometimes we want to keep some sort of local state during watching of the store. Let's say we have store:
and we watch it, but we only want to output new information to the console on every 10th change.
We can accomplish it like:
useWatch
Works the same way as regular watch
method, excepts it'll automatically stop listening to changes when component unmounts
useView
caution
This feature is experimental
Instead of wrapping your functional components with view
, you can call useView
before reading any value from the store
- view
- useView
WatchContext
caution
This feature is experimental
This one is useful when you use 3rd party components or have some large components you don't want to modify.
By default (stable solution) you can use useUpdateOnAnyChange
described in hooks section.
info
useUpdateOnAnyChange
is stable and is safe to be used. It is shown here only as an example
This will work just fine, but the downside of it is that it will cause your component to re-render on any provided store part change, even if it was never used.
Instead, we can wrap 3rd party or component we dont want to modify with WatchContext
:
This way, WatchContext
will re-render only when any value used by any (even deeply nested) child changes.