Tomasz Olek Posted December 27, 2022 Posted December 27, 2022 Hi, I wanted to create a vertical/horizontal scroll but I've meet a problem where when using react 18, project just dont work. Could someone help me fix this issue so I can use react 18?https://codesandbox.io/s/test-forked-i9ng90?file=/src/App.js
Solution GreenSock Posted December 27, 2022 Solution Posted December 27, 2022 Welcome to the forums, @Tomasz Olek! It looks like you just weren't doing proper cleanup. React 18 actually calls useEffect() TWICE in strict mode which catches a lot of people by surprise. It's quite unintuitive in my opinion. So due to that React behavior, you ended up creating multiple tweens/ScrollTriggers that were competing to control the same things simultaneously. The new gsap.context() is your new best friend in React. I'd strongly recommend reading this article: Here's a fork where all I changed was wrapping your code in a gsap.context() and then calling revert() on it in the cleanup function: https://codesandbox.io/s/test-forked-sw2bh7?file=/src/App.js Does that clear things up? 1
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