react-query-kit icon indicating copy to clipboard operation
react-query-kit copied to clipboard

`skipToken` usage

Open vlanemcev opened this issue 1 year ago • 2 comments

Hi, thanks for this amazing library!

I'm curious how to use skipToken functionality with createQuery function options. This is pretty useful for refetch preventing if we have our query disabled.

https://tanstack.com/query/v5/docs/framework/react/guides/disabling-queries#typesafe-disabling-of-queries-using-skiptoken

vlanemcev avatar May 09 '24 12:05 vlanemcev

To disable queries, now you can pass skipToken as the option variables to your custom query in v3.3.0. This will prevent the query from being executed.

import { skipToken } from '@tanstack/react-query'

const [name, setName] = useState<string | undefined>()
const result = usePost({
  variables: id ? { id: id } : skipToken,
})

// and for useQueries example
const queries = useQueries({
  queries: [usePost.getOptions(id ? { id: id } : skipToken)],
})

liaoliao666 avatar May 10 '24 03:05 liaoliao666

Okay, thanks!

vlanemcev avatar May 10 '24 15:05 vlanemcev