Sep 9, 2018 · 1 min read
Thanks for suggesting the changes. ☺
- 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.
- 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.
