
nickraps
-
Posts
20 -
Joined
-
Last visited
Content Type
Profiles
Forums
Store
Blog
Product
Showcase
FAQ
ScrollTrigger Demos
Downloads
Blog Post Comments posted by nickraps
-
-
Note that we are using
useState
instead ofuseRef
with the timeline. This is to ensure the timeline will be available when the child renders for the first time.Why is this necessary? Why could it be not available if you don’t create it as a state?
The timeline is just an object right?
-
Great article! Many useful tips.
-
1
-
GSAP + React, Advanced Animation Techniques.
in Learning Center
Posted
@OSUblake
Thanks for the explanation!
I see your point. I agree if you create the timeline in the component function, it should be always in a hook like useState or useRef to prevent creating new ones.
However, what if you just create the timeline as a plain variable in the same file as the component, but not in the actual component function? That way, a new timeline also won't be created even if the component re-renders. I guess in this particular case it also works.