notifyOnChangeProps
to also accept a callback
#5588
Replies: 3 comments 19 replies
-
I think the react way would be to unmount the component if it's going to be "hidden" |
Beta Was this translation helpful? Give feedback.
-
Hey @TkDodo! I have a branch ready and would like to open a PR. However I might not have permissions to push to a branch. What is the best away to do so? 🙏 |
Beta Was this translation helpful? Give feedback.
-
Thank you so much @TkDodo for merging the PR: #5734 A few more questions that could further improve this experience. We tried this approach, since it's now live, and we hit what I described here: #5588 (reply in thread) Whenever a fetch happens, if a component is not listening to any prop changes it could end up with "outdated" data. To fix this, we could call So how could we get a screen/component to re-render/get the latest data from cache?
What are your thoughts @TkDodo? Thank you once again for all you support! 🙇 |
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 TanStack team!
First of all, thank you for your amazing work with the TanStack/query 🚀
Problem
With
notifyOnChangeProps
we can make a component only re-render if any of the listed properties change. This is very useful and we can completely stop all re-renders if needed with an empty array[]
.We have a use case where we want to completely disable re-renders that would come from data fetching when components go into an "hidden"/"sleep" state.
This is achievable by setting component state and use that as a condition to pass in a different
notifyOnChangeProps
value.Basic Example:
So, if any other component uses the same
queryKey
to update the data, the component won't re-render.However, this still requires one extra re-render to change the
notifyOnChangeProps
value and we have a use case where the extra re-render could be considered expensive.Proposal
The
notifyOnChangeProps
would be extended to also accept a callback. The return type of this callback would bestring[] | "all"
.This way, we could change the return value of
notifyOnChangeProps
without an extra re-render.Basic Example:
Unknowns
I'm still unsure if there would be any side-effects by opting for a callback instead.
From the example above, the only probable side-effect I'm able to think of is that the data wouldn't be immediately up to date if the component stopped being hidden, probably requiring a manual "refetch" or wait for another data fetch.
Beta Was this translation helpful? Give feedback.
All reactions