Jump to content
Search Community

Scrolltigger getting error on react js

JentiDabhi test
Moderator Tag

Recommended Posts

I am trying to add scroll trigger on page in react js componentDidmount() function but its getting error when we click to other page

ERROR:
Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method.

Here is my code:

  async componentDidMount() {

 

    let isMounted = true
 
    gsap.to('#root'1, {
      css: { opacity: '1' }
    })
 
    
    let pageContainer = document.querySelector(".carsoul--onScroll");
    let container = document.getElementById("on--scroll-team");
    this.tl.to(pageContainer, {
      x: function x() {
        return -(container.scrollWidth - document.documentElement.clientWidth) + "px";
      },
      ease: Linear.easeInOut,
      scrollTrigger: {
        trigger: container,
        invalidateOnRefresh: true,
        pin: true,
        scrub: 1,
        start: "top top",
        //markers: true,
        end: function end() {
          return "+=" + pageContainer.offsetWidth;
        }
      }
    });
    
 
  }
componentWillUnmount (){
    this.tl.kill()
  }
Link to comment
Share on other sites

Please provide a minimal demo. It's hard to say what's going on from a code snippet.

 

And why do you have async on there? Sounds like you have something else going on, like a promise.

https://stackoverflow.com/questions/52061476/cancel-all-subscriptions-and-asyncs-in-the-componentwillunmount-method-how

 

And you should probably kill it like.

this.tl.scrollTrigger.kill();
this.tl.kill();

 

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