Skip to content

Commit

Permalink
fix: remove unnessary logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Innei committed Aug 25, 2023
1 parent b1aaa93 commit e977674
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions src/hooks/common/use-is-active.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
import { useSyncExternalStore } from 'react'

const listeners = new Set<() => void>()
const subscribe = (listener: () => void) => {
listeners.add(listener)
const handler = function () {
listeners.forEach((listener) => listener())
}
document.addEventListener('visibilitychange', handler)

const subscribe = (cb: () => void) => {
document.addEventListener('visibilitychange', cb)
return () => {
document.removeEventListener('visibilitychange', handler)
listeners.delete(listener)
document.removeEventListener('visibilitychange', cb)
}
}

const getSnapshot = () => document.visibilityState === 'visible'
const getServerSnapshot = () => true
export const usePageIsActive = () => {
return useSyncExternalStore(
subscribe,
() => document.visibilityState === 'visible',

() => true,
)
return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot)
}

1 comment on commit e977674

@vercel
Copy link

@vercel vercel bot commented on e977674 Aug 25, 2023

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:

shiro – ./

shiro-git-main-innei.vercel.app
innei.in
shiro-innei.vercel.app
springtide.vercel.app

Please sign in to comment.