-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refetch on window focus #422
Labels
core
Feature requests related to core functionality
Comments
+1 for this |
+1 |
3 similar comments
+1 |
+1 |
+1 |
+2 |
This is how I do it right now. this code will be added globally where we include apollo provider useEffect(() => {
const refetchQueries = () => {
if (document.visibilityState === "visible") {
client.refetchQueries({ include: "active" });
}
};
window.addEventListener("visibilitychange", refetchQueries);
return () => {
window.removeEventListener("visibilitychange", refetchQueries);
};
}, []); |
+1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Libraries such as SWR and React Query support opting into queries re-fetching upon the window being re-focused.
They allow to you configure this behavior on a per-query or on a global level. It seems quite popular and might be a feature Apollo would like to support.
Example from React Queries docs
A previous issue (feature request) had a lot of comments on it asking for Apollo to support the feature.
To implement this feature in Apollo current, you have to do the following.
On a global level:
On a per-query level:
#247 (comment)
Specifically:
The use case seems fairly common and might be something to consider bringing into Apollo as a feature.
The text was updated successfully, but these errors were encountered: