T
TanStack4y ago
ambitious-aqua

I want to get when I click on a function

I have a get request but I don't want it to work in every render, I want this request to happen only when the function is pressed, what should I do? I made enabled:false in the settings and I am using the refetch method but when another component is rendered it refreshes the request
2 Replies
correct-apricot
correct-apricot4y ago
Using useMemo/useCallback would solve your problem since it would not re-render the component when nothing has changed to it ?
absent-sapphire
absent-sapphire4y ago
Disabling/Pausing Queries | TanStack Query Docs
If you ever want to disable a query from automatically running, you can use the enabled = false option. When enabled is false:

Did you find this page helpful?