Jump to content
Search Community

Staggering an Array of React Components

TheBluerock test
Moderator Tag

Recommended Posts

Hi guys.


I am trying to achieve an overlay menu animation using this stack: React, styled-components and gsap.


I made a simplified example of my code in here: https://codesandbox.io/s/young-wildflower-ld94q


The main overlay animation plays smoothly, but the menu items dont.


I am trying to create a stagger effect for each MenuItem component.

As you can see using useRef() hook only works only for the last component.


When Iterating an array of components useRef() is not the right choice since the same ref has been passed to multiple objects,

but still I have no idea how to get a progressive fade for each component and I'm not even sure I'm using gsap in the correct way.


What am I doing wrong?
Thank you in advance,

See the Pen by s (@s) on CodePen

Link to comment
Share on other sites

  • 1 year later...
18 hours ago, magicniclus said:

i would like to make a map an ref containing an array to ref but using a gsap.timeline()

I read that several times and I'm still lost as to what your goal is. 


Your code is using .map() but not assigning it to anything, so I'm struggling to see the point. I also don't understand why you're using two useEffect() calls instead of one. 


If you still need some help, it'd definitely be helpful if you could provide a minimal demo, like in CodeSandbox or CodePen. 👍

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...