Cristian Flórez
Cristian Flórez

Reputation: 2781

stateTime vs refetchOnMount to avoid refetch on each component mount

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.

Upvotes: 0

Views: 559

Answers (1)

skndstry
skndstry

Reputation: 671

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.

Upvotes: 1

Related Questions