Jump to content
Search Community

reverse() stoped working after i add setState

AwSick test
Moderator Tag

Go to solution Solved by OSUblake,

Recommended Posts

Hi AwSlick,

 

You should never create a timeline at the top level of a function. Once you change the state, your component will re-render, and it's going to create a brand new timeline, so you will be referencing a completely different timeline.

 

This is explained in our React Guides.

 

 

  • Like 2
Link to comment
Share on other sites

25 minutes ago, OSUblake said:

Hi AwSlick,

 

You should never create a timeline at the top level of a function. Once you change the state, your component will re-render, and it's going to create a brand new timeline, so you will be referencing a completely different timeline.

 

This is explained in our React Guides.

 

 

 hi, i checked ur link, but still not understand how to fix my problem, can u please show solution on example if possible

Link to comment
Share on other sites

  • Solution

Do not create a timeline or tween at the top level of function.

 

// BAD
const Envelope = () => {
  const t1 = gsap.timeline({ paused: true, reversed: true });
}

// GOOD
const Envelope = () => {
  const tl = useRef();
  
  useEffect(() => {
    t1.current = gsap.timeline({ paused: true, reversed: true });
  }, []);  
}

 

Go back and look at the demos, like the one in the Creating and controlling timeline section.

 

See the Pen eYWGeGe by GreenSock (@GreenSock) on CodePen

 

  • Like 2
Link to comment
Share on other sites

10 minutes ago, OSUblake said:

Do not create a timeline or tween at the top level of function.

 

// BAD
const Envelope = () => {
  const t1 = gsap.timeline({ paused: true, reversed: true });
}

// GOOD
const Envelope = () => {
  const tl = useRef();
  
  useEffect(() => {
    t1.current = gsap.timeline({ paused: true, reversed: true });
  }, []);  
}

 

Go back and look at the demos, like the one in the Creating and controlling timeline section.

 

 

 

 

Thanks a lot !! , now i understand, its works.

  • Like 1
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...