I have a request which I run when the component is mounted, what I want is to avoid this request running in each of the component re-mounts. I have reviewed the documentation and I have found two possible solutions, stateTime: Infinity
and refetchOnMount: false
, with both options I get the component to only run the request once, I want to know the pros and cons of each option or if there is any option that I have not taken into account that fits better for this use case.
CodePudding user response:
Do not set staleTime
to Infinity
. Please take a moment to read the docs on important react-query concepts, such as staleTime
: React-Query Important Defaults
Having the request run again after a little while for validation should be perfectly fine. If you mutate anything in the backend with your request, use mutations.