Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can I get a callback if an element is in view for more than x seconds? #150

Open
ArbaazDossani opened this issue Jan 14, 2019 · 1 comment

Comments

@ArbaazDossani
Copy link

I need a callback if the user has stopped scrolling and an element is in view for more than x seconds

@ghost1face
Copy link

This can probably be done by separating your components and using lifecycle hooks (ComponentDidMount & ComponentWillUnmount), for example:

class MyComponent extends React.PureComponent {
   componentDidMount() {
     this._timeout = setTimeout(() => {
         // make request after being mounted for 5 seconds
     }, 5000);
  }

  componentWillUnmount() {
     clearTimeout(this._timeout);
  }
}

<VisibilitySensor>
    {({isVisible}) => <MyComponent />
</VisibilitySensor>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants