Soumyajit Pathak
Sep 9, 2018 · 1 min read

Thanks for suggesting the changes. ☺

  1. Calling the event handler in both the cases (with the forced flag) is to stress the fact that we need forcibly apply some external logic apart from the Page Visibility API. The verbosity is harmless here and only meant to underline the fact that we are forcing the visibility change. Your way is certainly the cleaner and better way in a production environment.
  2. Colocating the event listener code is just to make it easier to follow the code flow. Less context switching. I did not want abstract away too much of the inner working.

I meant for this tutorial to highlight how to reuse inconsistent browser APIs (the ones with browser inconsistencies or the ones that require minor patching) in the context of React.

Certainly not production ready npm package level code.

Soumyajit Pathak

Written by

JavaScript. React. GraphQL. Node. Web Animation. Open Source. Random words.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade