import { useQuery } from 'react-query' ; import { getCompany , CompanyRes } from '../api' ; async function fetchCompany ( { queryKey } ) { const [ _key , id ] = queryKey ; return await getCompany ( id ) ; } export function useCompany ( companyId ? ) { return useQuery ( companyId && [ 'companies' , companyId ] , fetchCompany ) ; }