T
TanStack3y ago
genetic-orange

React Query Disable

In my case how can I delay the API call, untill visible set to true
const [visible, setVisible] = useState<boolean>(false);

const {
isError: voyageStartError,
isLoading: voyageStartLoading,
fetchStatus: voyageStartFetchStatus,
} = useGetQuery<IVoyageLocations, IVoyageGet>(
['getStartVoyageLocation', startPoint],
`voyages/locations/${startPoint}`,
{
id: null,
},
visible
);

const {
isError: voyageEndError,
data: voyageEndData,
isLoading: voyageEndLoading,
} = useGetQuery<IVoyageLocations, IVoyageGet>(
['getEndVoyageLocation', endPoint],
`voyages/locations/${endPoint}`,
{
id: null,
},
visible
);

if (

) {
return <Loading />;
}

if (voyageStartError || voyageEndError) {
return <ErrorOccurred />;
}

const [visible, setVisible] = useState<boolean>(false);

const {
isError: voyageStartError,
isLoading: voyageStartLoading,
fetchStatus: voyageStartFetchStatus,
} = useGetQuery<IVoyageLocations, IVoyageGet>(
['getStartVoyageLocation', startPoint],
`voyages/locations/${startPoint}`,
{
id: null,
},
visible
);

const {
isError: voyageEndError,
data: voyageEndData,
isLoading: voyageEndLoading,
} = useGetQuery<IVoyageLocations, IVoyageGet>(
['getEndVoyageLocation', endPoint],
`voyages/locations/${endPoint}`,
{
id: null,
},
visible
);

if (

) {
return <Loading />;
}

if (voyageStartError || voyageEndError) {
return <ErrorOccurred />;
}

2 Replies
genetic-orange
genetic-orangeOP3y ago
I cannot find a solution for this
stormy-gold
stormy-gold3y ago
You want to pass { enabled: visible } to your useQuery call

Did you find this page helpful?