manifold/web/hooks/use-ping.ts

17 lines
385 B
TypeScript
Raw Permalink Normal View History

2022-07-17 20:17:31 +00:00
import { useEffect } from 'react'
import { updateUser } from 'web/lib/firebase/users'
export const usePing = (userId: string | undefined) => {
useEffect(() => {
if (!userId) return
const pingInterval = setInterval(() => {
updateUser(userId, {
lastPingTime: Date.now(),
})
}, 1000 * 30)
return () => clearInterval(pingInterval)
}, [userId])
}