useLazyQuery #1205
Replies: 4 comments 19 replies
-
Because the core API allows for this already, this request is more of a stylistic change that won't apply to everyone. For that reason, the official recommendation is to make your own custom hook like so: export default function useLazyQuery (key, fn, options = {}) {
const query = useQuery(key, fn, {
...options,
enabled: false
})
return [query.refetch, query]
} Using something akin to this hook will allow you to create any type of API interface to |
Beta Was this translation helpful? Give feedback.
-
An even easier approach is to just use |
Beta Was this translation helpful? Give feedback.
-
I ended up doing something like this. I also wanted the Fix the types yourself. This is inspired from
|
Beta Was this translation helpful? Give feedback.
-
Here is a simple implementation via ensureQueryData, see more here, https://tanstack.com/query/latest/docs/reference/QueryClient#queryclientensurequerydata |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Please add a hook
useLazyQuery
. It is inconvenient to specify the parameterenabled: false
every time.For expample:
const [fetch, { isLoading, data }] = useLazyQuery('key', () => axios.get('/bla-bla-bla'))
The parameter
throwOnError
needs to workthrowOnError: true
.For example:
throwOnError: true
- do not workingBeta Was this translation helpful? Give feedback.
All reactions