fkhadra / react-on-screen

Check if a react component in the viewport
https://fkhadra.github.io/react-on-screen/
MIT License
405 stars 50 forks source link

Delay componentDidMount checking to allow for styles to mount #13

Closed tapayne88 closed 6 years ago

tapayne88 commented 6 years ago

Hi, I'm using aphrodite to style my child component and what I've found is that to do any DOM calculations I need to push the computation into the next tick as the styles don't get applied in the same tick as the mounting.

Happy to submit a pull request.

Cheers, Tom

fkhadra commented 6 years ago

Hey @tapayne88,

It's a good idea. Any pull request is welcome 👍 . You already have an idea how you would implement it ?

tapayne88 commented 6 years ago

Yeah, was going to update componentDidMount to:

componentDidMount() {
  this.attachListener();
  setTimeout(() => this.isComponentVisible(), 0);
}

Could potentially assign to a variable and clear on unmount but won't have thought it would every fire after a component unmounts

tapayne88 commented 6 years ago

17