Skip to content

Instantly share code, notes, and snippets.

View estebangarviso's full-sized avatar
🏠
Working from home

Esteban Garviso estebangarviso

🏠
Working from home
View GitHub Profile
@AnishLushte07
AnishLushte07 / usePageVisibility.js
Last active April 21, 2024 08:02
ReactJS custom hook for page visibility change. Track tabs and window switch.
/*
* This react hook tracks page visibility using browser page visibility api.
* Reference: https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API
*
* Use: const pageVisibilityStatus = usePageVisibility();
* Return type: boolean
*/
import { useState, useEffect } from 'react';