Jump to content
Search Community

Animations restart when an unrelated component button is clicked in Nextjs

kvncnls test
Moderator Tag

Go to solution Solved by kvncnls,

Recommended Posts

// Parent Component
export default function ParentComponent() {

  const [title, setTitle] = useState('values');

  const changeContent = (title) => {

  const bgRef = useRef(null);
  const mainRef = useRef(null);
  const bgTransitionRef = useRef(null);

    const tl = gsap.timeline();

        {y: 0, skewY: 0},
        {y: "-120vh", skewY: 4, duration: 1.2, ease: "power4.inOut"})
        {filter: "brightness(3) grayscale(150%)"},
        {filter: "brightness(1) grayscale(0%)", duration: 1.2})
        {y: 150, autoAlpha: 0},
        {y: 0, autoAlpha: 1, duration: 1.2, ease: "power3.inOut"}, "<0.5")
  return (
    <div className="parent-component">
    	<img className='bg-background' src="/assets/clouds.png" ref={bgRef} />
        <div className="bg-transition" ref={bgTransitionRef} ></div>
    	<ChildComponent changeContent={() => changeContent('values')} />

// Child Component

export default function ChildComponent(props) {

  return (
    <div className="child-component" onClick={props.changeContent}>

Alrighty, so what's happening is that whenever I click the ChildComponent, it should run a function called 'changeContent'.

It does change the content when I click it. But what it also does is that it restarts all of the GSAP animations.

Why is it doing this? And how can I prevent it from happening?

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...