[Question] Best practice for using Animated nodes in functional components / hooks
See original GitHub issueWhen using animated nodes in functional components or inside custom hooks, simply assigning them to a variable (in every render) seems to work fine, but is there a significant cost or other issue to it?
I started out using useMemo like this, because I thought that would match what I was doing before with class fields:
const saw = useMemo(() => Animated.sub(1, ramp), [ramp]);
But maybe it’s not neccessary at all?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:10 (4 by maintainers)
Top Results From Across the Web
React Hooks cheat sheet: Best practices with examples
In this tutorial, we'll outline some React Hooks best practices and highlight some use cases with examples, from simple to advanced scenarios.
Read more >Let's play with React Hooks: From a Function Component to a ...
In this example I'm going to walk you through adding state and animation to a function component using hooks. I'm making use of...
Read more >45 Advanced React Interview Questions (With Hooks) Devs ...
Check 45 Advanced React Interview Questions (With Hooks) Devs Must Clarify and Know and Land Your Next Six-Figure Job Offer! 100% Tech Interview...
Read more >Generating new component types in react hooks, how to ...
I'm asking how to maintain performance while generating functional components inside a hook. Using this pattern would be a nice way to reduce ......
Read more >React Function Components
As you have seen, React Hooks enable us to use state in React (Arrow) Function Components. Whereas you would have used a setState...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks to this video https://www.youtube.com/watch?v=1Q9efh7OcR8 from William Candillon, I managed to get my head around using the library with functional components. Here is my solution highly inspired from the video.
when
isVisible
change, the animation is restarted and theanimation
value get interpolated again in the other direction, from 0 to 1, or 1 to 0 depending on the visibility flag.I hope this would help people having difficulty with functional component implementation and reanimated.
@alwex What about gesture based animations ? because the state change at the middle of running animations seems to interrupt the animation 🤕
or at least in my case 😄 before I get to know useMemoOne , I used to define some animation values outside of the component function so they won’t get rerender and reset every time state changes