manifold/web/hooks/use-users.ts
Marshall Polaris acc9c84e2e
More absolute imports (#156)
* Configure functions module to allow absolute imports

* Convert common imports in functions to be absolute

* Convert common imports in web to be absolute

* Convert lib imports in web to be absolute

* Convert hooks imports in web to be absolute

* Convert components imports in web to be absolute
2022-05-09 09:04:36 -04:00

40 lines
760 B
TypeScript

import { useState, useEffect } from 'react'
import { PrivateUser, User } from 'common/user'
import {
getUser,
listenForAllUsers,
listenForPrivateUsers,
} from 'web/lib/firebase/users'
export const useUsers = () => {
const [users, setUsers] = useState<User[]>([])
useEffect(() => {
listenForAllUsers(setUsers)
}, [])
return users
}
export const useUserById = (userId?: string) => {
const [user, setUser] = useState<User | undefined>(undefined)
useEffect(() => {
if (userId) {
getUser(userId).then(setUser)
}
}, [userId])
return user
}
export const usePrivateUsers = () => {
const [users, setUsers] = useState<PrivateUser[]>([])
useEffect(() => {
listenForPrivateUsers(setUsers)
}, [])
return users
}