Reputation: 475
I use react-query. The result value should be determined according to the query key. However, when it is a specific query key, api calls should not be made.
Is there any problem with the code below? I'm worried about breaking the react-query rules. please help me.
function useTest(a,b) {
const {
fetchNextPage,
data,
} = useInfiniteQuery(['test', a, b], ({ pageParam = 1 }) => {
if (b=== 3) { return; }
return fetchTest(pageParam, a)
}, {
cacheTime: 0,
staleTime: Infinity,
});
}
Upvotes: 1
Views: 3683
Reputation: 28978
I think react-query will wrap the result in a Promise anyways, so you can do:
useQuery(key, () => "foo")
as well. In your example, just be aware that data
can then be undefined
. It might be better to disable the query in this case:
useInfiniteQuery(['test', a, b], fetchTest, { enabled: b !== 3 })
Upvotes: 2