Skip to content

Commit

Permalink
docs: Fix usage of removeEventListener (#7393)
Browse files Browse the repository at this point in the history
  • Loading branch information
Oc1S committed May 10, 2024
1 parent ab126e8 commit 0bb0fa3
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions docs/framework/react/guides/window-focus-refetching.md
Expand Up @@ -50,10 +50,13 @@ In rare circumstances, you may want to manage your own window focus events that
focusManager.setEventListener((handleFocus) => {
// Listen to visibilitychange
if (typeof window !== 'undefined' && window.addEventListener) {
window.addEventListener('visibilitychange', () => handleFocus(), false)
const visibilitychangeHandler = () => {
handleFocus(document.visibilityState === 'visible')
}
window.addEventListener('visibilitychange', visibilitychangeHandler, false)
return () => {
// Be sure to unsubscribe if a new handler is set
window.removeEventListener('visibilitychange', () => handleFocus())
window.removeEventListener('visibilitychange', visibilitychangeHandler)
}
}
})
Expand Down

0 comments on commit 0bb0fa3

Please sign in to comment.