Description
react-page-visibility is a React component that wraps the browser's Page Visibility API, so your app knows when its tab is hidden or visible again. You can use it to stop polling a backend, or to pause animations, while the page is in the background, which saves bandwidth and processing. It is a higher-order component that you can use many times in one application without side effects. It handles the event listeners for you, so you do not need to add and remove them in your component lifecycle, and it checks browser support for you. Cross-browser support covers older browsers, including Internet Explorer and Safari, and there is a safe fallback when the API is missing. You can react to changes with an onChange callback, pass a function as children to render based on the visibility, or use the usePageVisibility hook in function components. The handler receives whether the page is visible and the visibility state. The README includes examples of a rotating carousel that pauses when the page is hidden. It is a small library for React developers who want to respond to the page being hidden without writing listener code.…
Highlights
- Declarative page visibility for React
- Higher-order component that can be nested
- usePageVisibility hook
- onChange callback and render-prop children
- Cross-browser support with a safe fallback
Ratings & Reviews
No ratings yet
Be the first to rate React Page Visibility.
People also visit

react-on-screen
A wrapper component to track if your react component is visible on screen
React Page Visibility FAQ
What does react-page-visibility do?
It tells a React component when the browser tab is hidden or visible, using the Page Visibility API.
Why use it instead of a helper function?
The README says the component manages the event listeners and the browser support checks for you.
How do I use it in a function component?
Use the usePageVisibility hook, as shown in the README.
Does it work in older browsers?
The README says it supports cross-browser use, including Internet Explorer and Safari, and falls back safely when the API is missing.
What is it useful for?
Pausing polling or animations while the page is in the background, to save bandwidth and processing.



















