manifold/web/hooks/use-ping.ts
2022-07-17 15:17:31 -05:00

17 lines
385 B
TypeScript

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])
}