tst-flopp Posted July 15, 2022 Share Posted July 15, 2022 import { useRef, useEffect } from "react"; import reactLogo from "./assets/react.svg"; function App() { const img = useRef(); useEffect(() => { gsap.from(img.current, { duration: 1, opacity: 0 }); }); const appStyle = { display: "grid", placeItems: "center", minHeight: "100vh", backgroundColor: "black", margin: "0", }; const imgStyle = { width: "250px", }; return ( <div className="App" style={appStyle}> <img ref={img} src={reactLogo} className="logo react" alt="React logo" style={imgStyle} /> </div> ); } export default App; This was my react code. other methods are working fine and in normal html javascript is fine also . but this one is not (gsap.from()). i am using vitejs as build tool. how can i fix this. Link to comment Share on other sites More sharing options...
Solution Cassie Posted July 15, 2022 Solution Share Posted July 15, 2022 Hey there - this is due to react 18's 'strict mode' It's a change in how React works - not a GSAP bug. More in the thread here - fix - useLayoutEffect(() => { let from = gsap.from(elem0.current, { rotation: 360, immediateRender: false }); return () => { from.kill(); }; }); 1 Link to comment Share on other sites More sharing options...
tst-flopp Posted July 15, 2022 Author Share Posted July 15, 2022 Cassie Evans thanks a lot this help me a lot. 1 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