More smart refetchOnMount #6676
Replies: 3 comments 1 reply
-
Another idea is to have |
Beta Was this translation helpful? Give feedback.
-
What's your use case? What about a stale time of Other than that: I like your approach. But is having an observer a good metric for not being outdated? I don't think so. |
Beta Was this translation helpful? Give feedback.
-
@TkDodo I do need your opinion, please) You know everything about react-query) |
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.
-
Hey)
I have an example of usage of the same query in two different React-components: https://codesandbox.io/p/sandbox/refetchonmount-getobservercount-kd88g2?file=%2Fsrc%2FApp.js%3A13%2C2 The second component appears only after "Show Comp2!" button click.
In a console you can see a log from api call, cause
<Comp1 />
uses useAppQuery. And you will see another log from api after<Comp2 />
mount, cause useAppQuery is used there too. I'm talking about react-query usage with defaults from react-query.But it is useless for me, when the second call of useAppQuery in
<Comp2 />
triggers api call. So, as I can see it from docs, I can pass a function torefetchOnMount
option. Like here (commented): https://codesandbox.io/p/sandbox/refetchonmount-getobservercount-kd88g2?file=%2Fsrc%2Findex.js%3A12%2C10-12%2C24 I can check, that current query does not have any active observers. And if there are no any observes — we should refetch. And we do not refetch otherwise.So, is it a good idea? Do you see any problems?
I can see only one problem, that
<Comp2 />
can have outdated data. But invalidation should work (cause<Comp1 />
is mounted).@TkDodo may be you can give me some ideas =)
Beta Was this translation helpful? Give feedback.
All reactions