how to pass params to useCustom when queryoptions.enabled is false
hi,when i click the button i want pass dynamic id to useCustom,how to make it? thanks
3 Replies
Hi @langziyang. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
To pass dynamic parameters to
useCustom
when queryOptions.enabled
is set to false
, you can use the config
property of useCustom
along with the refetch
function. Here's how you can modify your code to achieve this:
In this approach:
1. We move the id
parameter from the URL to the config.query
object in useCustom
.
2. When calling refetch
, we pass the dynamic id
value in the config.query
object.
This way, you can dynamically update the id
parameter when refetching the data.
For more information on using useCustom
and its properties, you can refer to the useCustom documentation (https://refine.dev/docs/data/hooks/use-custom/#properties).
Remember that when queryOptions.enabled
is set to false
, the query will not automatically run on component mount. It will only run when you manually trigger it using the refetch
function.
useCustom API Reference (https://refine.dev/docs/data/hooks/use-custom/#api-reference) provides more details on the available properties and usage of the useCustom
hook.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@546172394226581514> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
robust-apricot•2mo ago
Hello @langziyang, Refine uses TanStack Query under the hood and it's not possible to refecth with new params.
this blog covers your use case.
https://tkdodo.eu/blog/react-query-fa-qs#how-can-i-pass-parameters-to-refetch
You need to change
id
state and useCustom will be triggered on new render with new idReact Query FAQs
Answering the most frequently asked React Query questions