manifold/web/hooks/use-contract.ts

13 lines
380 B
TypeScript
Raw Normal View History

2021-12-09 22:05:55 +00:00
import { useEffect, useState } from 'react'
import { Contract, listenForContract } from '../lib/firebase/contracts'
export const useContract = (contractId: string) => {
const [contract, setContract] = useState<Contract | null | 'loading'>('loading')
useEffect(() => {
if (contractId)
return listenForContract(contractId, setContract)
}, [contractId])
return contract
}