-
Notifications
You must be signed in to change notification settings - Fork 8
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
Focus aware query polling #856
Conversation
Apollo does not support pausing polling when the current browser tab is not in focus (see [feature request](apollographql/apollo-feature-requests#247)). Therefore we add our own `useFocusAwareQuery` hook that wraps `useQuery` and pauses/resumes polling upon focus/blur.
better would be to avoid wrapping the hook, as you can only wrap once - to get one feature - but not twice. Some HOC system that let's the user do comoposition is a possible solution - but overkill in this case. Some kind of additional hook is nice imho (downside: not so easy to use as yours) possible alternative: comet-admin has it's own |
@nsams what would you say to a solution like this? const { data, startPolling, stopPolling, refetch } = useQuery(...);
useFocusAwarePolling({ pollInterval: 10000, startPolling, stopPolling, refetch }); |
👍 (not so easy to use, but still preferable for the aforementioned reason) |
Wrapping the hook is not desirable as the hook can only be wrapped once. We therefore move the focus aware polling into a separate `useFocusAwarePolling` hook.
Done in ac42702. Also added docs on how to use. |
did you forget to |
No, they're right here: bad684a. |
Apollo does not support pausing polling when the current browser tab is not in focus (see feature request). Therefore we add our own
useFocusAwareQuery
hook that wrapsuseQuery
and pauses/resumes polling upon focus/blur.