useDynamicAnimation
useDynamicAnimation is a hook that lets you use style objects dynamically, rather than using static variants.
It has all the same performance benefits of useAnimationState, with a more expressive API.
useDynamicAnimation(initialState?)#
Benefits#
- High performance
- Zero re-renders
- Animations run on the native thread
- Easy API
Arguments#
Receives one (optional) argument: a pure function which returns the initial state. This is similar to React useState's first argument.
Returns#
current#
Get the current animation state. Unlike useState's return value, this can be safely read and accessed synchronously.
animateTo(next)#
A function to animate to your next state. This is a worklet, so you can call it from the native thread.
You can also pass a function which receives the current style and returns the next state:
Do not destructure#
Sequences#
Any Moti styles are valid here. For example, if you want a sequence animation, just pass an array.