import { Record } from '../types' ; import { Refetch , useGetMany } from '../dataProvider' ; interface Option { id : string ; reference : string ; } export interface UseReferenceProps { loading : boolean ; loaded : boolean ; referenceRecord ? : Record ; error ? : any ; refetch : Refetch ; } typedef ReferenceProps property { boolean } loading property { boolean } loaded property { Object } referenceRecord example param option param { string } option . reference param { string } option . id returns { ReferenceProps } export const useReference = ( { reference , id } ) : UseReferenceProps => { const { data , error , loading , loaded , refetch } = useGetMany ( reference , [ id , ] ) ; return { referenceRecord : error ? undefined : data [ 0 ] , refetch , error , loading , loaded , } ; } ; export default useReference ;