manifold/web/hooks/use-user.ts

16 lines
404 B
TypeScript
Raw Normal View History

2021-12-09 22:05:55 +00:00
import { useEffect, useState } from 'react'
import { listenForLogin, listenForUser, User } from '../lib/firebase/users'
2021-12-09 22:05:55 +00:00
export const useUser = () => {
2021-12-16 07:00:35 +00:00
const [user, setUser] = useState<User | null | undefined>(undefined)
2021-12-09 23:37:26 +00:00
useEffect(() => listenForLogin(setUser), [])
const userId = user?.id
useEffect(() => {
if (userId) return listenForUser(userId, setUser)
}, [userId])
2021-12-09 23:23:21 +00:00
return user
}