Hey there,
Trying to animated mapped components in my Next.js app.
I have succeeded, but something is off..
The animation is not 'fluid'. See clip. I noticed it does not happen with 'a hardcoded array of items'.
I also tried to grab all the buttons using gsap.utils.toArray(#button), but the same happens.
How can I adjust the code for it to be fluent?
Screen Recording 2025-09-18 at 11.55.28.mov
Here is my code:
const buttonRefs = useRef<HTMLAnchorElement[]>([]);
buttonRefs.current = [];
tl.fromTo(
buttonRefs.current,
{ autoAlpha: 0, yPercent: 100 },
{ autoAlpha: 1, yPercent: 0, ease: "linear", stagger: 0.1 }
);
}, []);
const addToRefs = (el: HTMLAnchorElement | null) => {
if (el && !buttonRefs.current.includes(el)) {
buttonRefs.current.push(el);
}
};
<div className="flex flex-row gap-4 w-fit">
{slice.primary.cta_buttons.map((item) => (
<Button
ref={addToRefs}
key={item.link.text}
className="text-body-base font-medium"
buttonStyle={item.style ?? "primary"}
field={item.link}
>
{item.link.text}
</Button>
))}
</div>
Much appreciated!