useMotiPressables()
useMotiPressables
lets you access the interaction state of multiple MotiPressable
parents. This lets you combine multiple different interactions and build animation states with ease.
#
Usage#
Walk ThroughImagine we have a list. The outer container component is a MotiPressable
, and each item has a MotiPressable
too.
Now, the ListItem
component can call useMotiPressables
instead of useMotiPressable
.
Say we want to make all items fade away when you hover over the list, except for the actual item you're hovering.
#
PerformanceThis hook runs on the native thread and triggers zero re-renders. Like all things moti, it has great performance out-of-the-box.
Similar to useMemo
, you can also pass in a dependency array as the last argument to reduce updates:
#
APIThe following usages are valid:
#
Argumentsfactory
is a worklet that returns a style object.- Its only argument is a
containers
dictionary, whose keys are theid
props of the containers, and the values are the derived values of each interaction state.
- Its only argument is a
id
is a unique string to identify the parentMotiPressable
component whose interaction state you're trying to access.deps
is a dependency array, just likeuseMemo
#
ReturnsA Moti state
object, meant to be passed to any Moti component's state
prop.