title: Check if the browser tab is in focus in ReactJS
body: <p>I have a website in ReactJS. I want to get a callback whenever my tab comes in focus or is hidden. I came across the Page Visibility API for this but I'm not able to figure out how to use it in ReactJS.</p>
  
  <p>In which lifecycle method do I register the callback for this?</p>