RTK Query's {skip: true} still calls the query on first render

Viewed 24

I'm performing a GET request with RTK Query, and want to delay the fetch to a button click (instead of having it automatically be called on page load). I tried to manually set a {skip: true} value in the query just to see that I can stop the initial query call, but it didn't work, the query still loads on first render and the isUnitialized argument that I'm destructuring from the query always returns false. The code below: const {isUninitialized} = useGetShipmentsQuery({skip: true}).

1 Answers

useGetShipmentsQuery({skip: true}) will send {skip: true} to the query function. You are passing it in as the first argument, which is that argument. If you want to set it as the options, it has to be the second argument.

So do

useGetShipmentsQuery(undefined, {skip: true})
//                   first arg   second arg
//                 arg to query  options
Related