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
29 lines
798 B
TypeScript
29 lines
798 B
TypeScript
import { useEffect, useState } from 'react'
|
|
import { Contract, listenForContract } from 'web/lib/firebase/contracts'
|
|
import { useStateCheckEquality } from './use-state-check-equality'
|
|
|
|
export const useContract = (contractId: string) => {
|
|
const [contract, setContract] = useState<Contract | null | 'loading'>(
|
|
'loading'
|
|
)
|
|
|
|
useEffect(() => {
|
|
if (contractId) return listenForContract(contractId, setContract)
|
|
}, [contractId])
|
|
|
|
return contract
|
|
}
|
|
|
|
export const useContractWithPreload = (initial: Contract | null) => {
|
|
const [contract, setContract] = useStateCheckEquality<Contract | null>(
|
|
initial
|
|
)
|
|
const contractId = initial?.id
|
|
|
|
useEffect(() => {
|
|
if (contractId) return listenForContract(contractId, setContract)
|
|
}, [contractId, setContract])
|
|
|
|
return contract
|
|
}
|