roniy35147 Posted January 3 Share Posted January 3 ScrolTriggerIssue_compressed.mp4 Link to comment Share on other sites More sharing options...
GSAP Helper Posted January 3 Share Posted January 3 Hi there! I see you're using React - Proper animation cleanup is very important with frameworks, but especially with React. React 18 runs in strict mode locally by default which causes your useEffect() and useLayoutEffect() to get called TWICE. Since GSAP 3.12, we have the useGSAP() hook (the NPM package is here) that simplifies creating and cleaning up animations in React (including Next, Remix, etc). It's a drop-in replacement for useEffect()/useLayoutEffect(). All the GSAP-related objects (animations, ScrollTriggers, etc.) created while the function executes get collected and then reverted when the hook gets torn down. Here is how it works: const container = useRef(); // the root level element of your component (for scoping selector text which is optional) useGSAP(() => { // gsap code here... }, { dependencies: [endX], scope: container }); // config object offers maximum flexibility Or if you prefer, you can use the same method signature as useEffect(): useGSAP(() => { // gsap code here... }, [endX]); // simple dependency Array setup like useEffect() This pattern follows React's best practices. We strongly recommend reading the React guide we've put together at https://gsap.com/resources/React/ If you still need help, here's a React starter template that you can fork to create a minimal demo illustrating whatever issue you're running into. Post a link to your fork back here and we'd be happy to take a peek and answer any GSAP-related questions you have. Just use simple colored <div> elements in your demo; no need to recreate your whole project with client artwork, etc. The simpler the better. 1 Link to comment Share on other sites More sharing options...
pepoge9978 Posted January 4 Share Posted January 4 On 1/3/2024 at 11:22 PM, GSAP Helper said: Hi there! I see you're using React - Proper animation cleanup is very important with frameworks, but especially with React. React 18 runs in strict mode locally by default which causes your useEffect() and useLayoutEffect() to get called TWICE. Since GSAP 3.12, we have the useGSAP() hook (the NPM package is here) that simplifies creating and cleaning up animations in React (including Next, Remix, etc). It's a drop-in replacement for useEffect()/useLayoutEffect(). All the GSAP-related objects (animations, ScrollTriggers, etc.) created while the function executes get collected and then reverted when the hook gets torn down. Here is how it works: const container = useRef(); // the root level element of your component (for scoping selector text which is optional) useGSAP(() => { // gsap code here... }, { dependencies: [endX], scope: container }); // config object offers maximum flexibility Or if you prefer, you can use the same method signature as useEffect(): useGSAP(() => { // gsap code here... }, [endX]); // simple dependency Array setup like useEffect() This pattern follows React's best practices. We strongly recommend reading the React guide we've put together at https://gsap.com/resources/React/ If you still need help, here's a React starter template that you can fork to create a minimal demo illustrating whatever issue you're running into. Post a link to your fork back here and we'd be happy to take a peek and answer any GSAP-related questions you have. Just use simple colored <div> elements in your demo; no need to recreate your whole project with client artwork, etc. The simpler the better. I use it and still the same issue right now I do little demo in Stackblitz Link Here ,thank for you suggestions i wish there's any solution for that https://stackblitz.com/edit/stackblitz-starters-nmv1q4?file=app%2F(images)%2F[id]%2Fpage.tsx Link to comment Share on other sites More sharing options...
GSAP Helper Posted January 4 Share Posted January 4 That Stackblitz isn't even loading for me. Maybe it's an issue with Stackblitz. 🤷♂️ But I'd strongly recommend trying to recreate the issue in a vanilla CodePen, without React, just to simplify and focus things. Note too that you should probably make sure you put a unit after each value in the inset(...), like "inset(0% 0% 100% 0%)". Once we see a simplified demo that illustrates the challenge, we'd be happy to offer some advice. Link to comment Share on other sites More sharing options...
pepoge9978 Posted January 4 Share Posted January 4 Thanks Link to comment Share on other sites More sharing options...
GreenSock Posted January 4 Share Posted January 4 Yeah, your link still didn't work for me. There are errors in the terminal. Is this what you're trying to do? https://stackblitz.com/edit/stackblitz-starters-knwv2m?file=app%2F(images)%2F[id]%2Fpage.tsx Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now