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 Through#
Imagine 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.
Performance#
This 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:
API#
The following usages are valid:
Arguments#
factoryis a worklet that returns a style object.- Its only argument is a
containersdictionary, whose keys are theidprops of the containers, and the values are the derived values of each interaction state.
- Its only argument is a
idis a unique string to identify the parentMotiPressablecomponent whose interaction state you're trying to access.depsis a dependency array, just likeuseMemo
Returns#
A Moti state object, meant to be passed to any Moti component's state prop.