acc9c84e2e
* 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
40 lines
760 B
TypeScript
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
|
|
}
|