-
Notifications
You must be signed in to change notification settings - Fork 787
useQuery keeps polling #3272
Comments
I also reproduced this bug. |
I'm using this workaround. const { loading, error, data, startPolling, stopPolling } = useQuery(GET_DELIVERIES_QUERY)
useEffect(() => {
startPolling(5000)
return () => {
stopPolling()
}
}, [startPolling, stopPolling]) |
@proutek Why do you need update effect when links to functions I am not sure is there a logic behind
Then effect will be |
Yes, you're right. I tried it before with empty array. I just wanted to get rid off the compiler warning.
Maybe I could try something like this facebook/create-react-app#6880 |
@proutek the thing is, this lint rule is cool for check yourself with dependencies but it's not much smart to separate them as required and not required because there is no checking types and logic behind our code. |
Here is the code work for me, but I am not sure it is the correct way or not. const { data, error, loading, stopPolling } = useQuery(GET_INVENTORY_DATA, {
pollInterval: 500
});
useEffect(() => {
return () => {
stopPolling();
};
}); |
* Add test for polling - update add link prop to the MockedProvider - add test that fails when component unmounted * fix useQuery polling unmounted bug * Re-arrange things a bit to remove extra `setTimeout` These changes will let us avoid the extra `setTimeout` call in the cleanup `useEffect`.
Just noticed when using the
useQuery
hook with a poll interval, the polling continues even when navigating to another page / hiding the component with the query in.Intended outcome:
The polling should stop when navigating away from the page with the query component / when the component is hidden (via state for example)
Actual outcome:
Polling continues
How to reproduce the issue:
https://codesandbox.io/s/apollo-react-query-component-f49si?fontsize=14
Click button to hide the component then check the network calls
Version
@apollo/react-hooks - 0.1.0-beta.11
The text was updated successfully, but these errors were encountered: