Detect when the tab is visible or hidden.
This is custom React hooks, you need to follow the Basic Rules when you use it.
Switch to another tab and back to see the value change.
const useDocumentVisibility = () => 'visible' | 'hidden'