Redux toolkit running multiple queries even with preventing it

Viewed 807

I'm using redux toolkit RTK with multiple hooks inside one single component, but the issue is that they are running together even I'm using the params skip which I dont want it in this case, here is my code:

const { data, isFetching } = useGetTestsQuery(filters, {
    pollingInterval: 5000
});

const {
    data: testsByStatus,
    isFetching: fetchDataByStatus
} = useGetTestsByStatusQuery(filters, {
    pollingInterval: 5000,
    skip: data
});
return <Table columns={columns} dataSource={data || testsByStatus} />;

in network tab I can see that both requests are running in same time, can I prevent eg. useGetTestsByStatusQuery from fetching while there are some data in useGetTestsQuery or vice-versa ?

1 Answers

Right now you are skipping if there is data and not skipping if there is no data.

You probably want to do

useGetTestsByStatusQuery(filters, {
    pollingInterval: 5000,
    skip: !data
});
Related