-
-
Notifications
You must be signed in to change notification settings - Fork 295
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement option to pause when document is hidden (#304)
* Implement option to pause when document is hidden * Add option to documentation * Rename pauseWhenDocumentHidden -> pauseWhenPageIsHidden for conciseness; improve documentation with examples --------- Co-authored-by: etcd <etcd>
- Loading branch information
Showing
4 changed files
with
53 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React from 'react'; | ||
|
||
export const useIsDocumentHidden = () => { | ||
const [isDocumentHidden, setIsDocumentHidden] = React.useState(false); | ||
|
||
React.useEffect(() => { | ||
const callback = () => { | ||
setIsDocumentHidden(document.hidden); | ||
}; | ||
document.addEventListener('visibilitychange', callback); | ||
return () => window.removeEventListener('visibilitychange', callback); | ||
}, []); | ||
|
||
return isDocumentHidden; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5bb5868
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
sonner – ./
sonner-git-main-emilkowalski-s-team.vercel.app
sonner-emilkowalski-s-team.vercel.app
sonner-toast.vercel.app
sonner.emilkowal.ski