HuolalaTech / react-query-kit

🕊️ A toolkit for ReactQuery that make ReactQuery hooks reusable and typesafe
MIT License
337 stars 11 forks source link

`skipToken` usage #53

Closed vlanemcev closed 4 months ago

vlanemcev commented 4 months ago

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

liaoliao666 commented 4 months ago

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)],
})
vlanemcev commented 4 months ago

Okay, thanks!