Home > other >  What is type of graphql refetch when passing as props?
What is type of graphql refetch when passing as props?

Time:12-16

I am passing graphql refetch to component as props, but I am not sure what should be the type?

const { data, loading, refetch } = useQuery(gqlquery, {
        variables: { where: { id: id } },
    });

  <myinfo
     loading={loading}
     data={data}
     refetch={refetch}
   />

export const myinfo= ({
    refetch,
    loading,
    data,
}: myinfoProps) => {}


type myinfoProps= {
    refetch?: any;
    loading: boolean;
    data: {}
};

I want to remove any from refetch?: any; what should be there instead of.

CodePudding user response:

From the docs, the type of refetch is :

 type myinfoProps= {
    refetch?: (options: { throwOnError: boolean, cancelRefetch: boolean }) => Promise<UseQueryResult>;
    loading: boolean;
    data: {}
};

While calling you will have to check if it is defined or not since it is an optional property :

export const myinfo= ({
    refetch,
    loading,
    data,
}: myinfoProps) => {
  if(refetch){
         refetch(/* parameters */);
    }

}
  • Related