Jump to content
Search Community

Import A custom hooks breaks animations, setState inside hook

Luis Pizarro test
Moderator Tag

Recommended Posts

I have 2 components with scroll animations using the gasp scrollTrigger for react.

In one of the components I called a custom hook that setState just the window width, height(not a too complex hook) on useEffect

I notice that is the issue with the animation, because I remove the import of that hook, or even I remove the set state  in the hook and it works fine.

Any suggestions on why this is happening?

Bad

https://drive.google.com/file/d/1WZ7MdUXjqDFct39wLLcJOI1RAuI2lhfi/view?usp=sharing

Good
https://drive.google.com/file/d/14i6B-AxWRT64WlyO0mSUIkVI3hhlcobw/view?usp=sharing

 

Link to comment
Share on other sites

Now that you mention the rerender, I'll take a look. For now I tried with this demo https://react-3ir25l.stackblitz.io but the issue is not happening here, at least with the demo I ant to know if this is a correct way to handle the timeline?. Because that might be an issue too, I have a timeline on each component. Something else that might be important is that I'm using Next.js rendering on server side might cause issues? I use next/dynamic to render them on client side but not sure if either option affects or not.

 

 

Actually sometimes I get this error  DOMException: Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node

Link to comment
Share on other sites

Guys I find the issue, thanks a lot mentioning that something might be causing a re-render make me focos on that.

On the component cleanup, we were calling  timeline.scrollTrigger.disable();

useEffect(() => {
console.log("mount1");
return () => {
timeline.scrollTrigger.disable();
console.log("unmount1");
};
},[]);

But on the useEffect we miss the [], so the component was mounting, unmounting, mounting. Causing that disable to run.

 

Also I had to run it on serverside, without that it keeps saying  DOMException: Failed to execute 'insertBefore' on 'Node':....

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