Jump to content
Search Community

Having a hard time converting 2 examples to React

newguy123 test
Moderator Tag

Go to solution Solved by GreenSock,

Recommended Posts

Hey, if you're using React make sure you read this article

 

And when sharing a Stackblitz link make sure you share  the edit url with a link to the file you've put your GSAP code in https://stackblitz.com/edit/react-i9fqyh?file=src%2FApp.js. If I look at this url I see three boxes moving the the right on scroll, so it seems to be working?

Link to comment
Share on other sites

10 minutes ago, mvaneijgen said:

Hey, if you're using React make sure you read this article

 

And when sharing a Stackblitz link make sure you share  the edit url with a link to the file you've put your GSAP code in https://stackblitz.com/edit/react-i9fqyh?file=src%2FApp.js. If I look at this url I see three boxes moving the the right on scroll, so it seems to be working?

no then I must have shared the wrong stackblits link. Look and my codesandbox link instead please

Link to comment
Share on other sites

I think you had not clicked save on the file before sharing. The original file you started with had the correct setup and I think you just removed everything and copied over the AirPods demo. 

 

In React you need to do proper cleanup in the useLayoutEffect function. I don't use React myself, but everything is explained in the example I've shared. My suggestion would be start with one of our React templates and copy over the logic you want one by one until something breaks. 

Link to comment
Share on other sites

57 minutes ago, mvaneijgen said:

I think you had not clicked save on the file before sharing. The original file you started with had the correct setup and I think you just removed everything and copied over the AirPods demo. 

 

In React you need to do proper cleanup in the useLayoutEffect function. I don't use React myself, but everything is explained in the example I've shared. My suggestion would be start with one of our React templates and copy over the logic you want one by one until something breaks. 

the problem is that those examples are simple little squares ande circles and getting directly animated, where the airpods thing has its own function doing things. Its that function I'm having a hard time with to convert to React.

 

Its getting the context of the canvas in the function, when the canvas is returned in the app, but the function is not seeing it for some reason

Link to comment
Share on other sites

Hi,

 

Sorry to hear about the troubles, but unfortunately we don't have the time resources to create this demo at this moment in React, but you're making some fundamental errors that most likely are causing the issues you're seeing.

 

First, when using animations in React, the React team recommends using the useLayoutEffect hook, in your code you have the helper function and then you execute the helper function in the global scope of the React component, at that point the DOM is not yet rendered, so there is no element to actually animate. This is mostly an issue with basic React concepts that, of course, gets into a GSAP issue since you're also not paying attention to the resources Mitchel has linked twice already in this thread. The React basics article is there for a reason and I strongly recommend you to read it in order to learn how to use GSAP in React apps, but first be sure to understand how a React component works and how to use the effect hooks (useEffect and useLayoutEffect) properly.

 

Good luck with your project.

Happy Tweening!

Link to comment
Share on other sites

19 hours ago, GreenSock said:

Maybe this will help nudge you in the right direction: 

https://stackblitz.com/edit/react-6u8izj?file=src%2FApp.js

Thanks Jack. Got pretty close to this, I just didnt add the initial framecount and url array into the useLayoutEffect
...and also forgot to import the ScrollTrigger from gsap/ScrollTrigger

On 11/13/2023 at 3:41 PM, mvaneijgen said:

Hey, if you're using React make sure you read this article

 

And when sharing a Stackblitz link make sure you share  the edit url with a link to the file you've put your GSAP code in https://stackblitz.com/edit/react-i9fqyh?file=src%2FApp.js. If I look at this url I see three boxes moving the the right on scroll, so it seems to be working?

Thanks, I looked at some of those. Probably needed to look at some of the more complex examples further down the page

23 hours ago, Rodrigo said:

Hi,

 

Sorry to hear about the troubles, but unfortunately we don't have the time resources to create this demo at this moment in React, but you're making some fundamental errors that most likely are causing the issues you're seeing.

 

First, when using animations in React, the React team recommends using the useLayoutEffect hook, in your code you have the helper function and then you execute the helper function in the global scope of the React component, at that point the DOM is not yet rendered, so there is no element to actually animate. This is mostly an issue with basic React concepts that, of course, gets into a GSAP issue since you're also not paying attention to the resources Mitchel has linked twice already in this thread. The React basics article is there for a reason and I strongly recommend you to read it in order to learn how to use GSAP in React apps, but first be sure to understand how a React component works and how to use the effect hooks (useEffect and useLayoutEffect) properly.

 

Good luck with your project.

Happy Tweening!

Yep, Understood

I may need to add additional sections to this and some other animated bits, but I'll ask for some help if/when I get there and if I can't figure it out on my own

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