manifold/web/hooks/use-fold.ts

24 lines
534 B
TypeScript
Raw Normal View History

2022-01-23 06:51:19 +00:00
import { useEffect, useState } from 'react'
import { Fold } from '../../common/fold'
2022-01-24 05:47:20 +00:00
import { listenForFold, listenForFolds } from '../lib/firebase/folds'
2022-01-23 06:51:19 +00:00
export const useFold = (foldId: string) => {
const [fold, setFold] = useState<Fold | null | undefined>()
useEffect(() => {
return listenForFold(foldId, setFold)
}, [foldId])
return fold
}
2022-01-24 05:47:20 +00:00
export const useFolds = () => {
const [folds, setFolds] = useState<Fold[] | undefined>()
useEffect(() => {
return listenForFolds(setFolds)
}, [])
return folds
}