[React Native] How to pause polling without re-render when a React Native screen gets out of focus #6002
-
Hi there, we have a couple screens in our React Native app that poll data regularly, like
and we would like to temporarily pause it when the screen gets out of focus, to avoid unnecessary network calls and screen updates (context: In React Native with To achieve this, we can use
It works great, but the problem is on the performance side. As @ferrannp well explained in #5588 (reply in thread),
We thought about using
So, I was just wondering if anyone has any ideas on how to pause query polling without causing a re-render when a React Native screen gets out of focus? Thanks in advance 🙏 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 13 replies
-
isn't that the reason we allowed
? |
Beta Was this translation helpful? Give feedback.
hmm, have you tried calling
refetchQueries
on the query that should poll manually once when you go back to thehome
tab? I'm thinking that this should re-trigger the interval function, and it works in this forked sandbox:https://codesandbox.io/s/rn-polling-demo-forked-yzvwzk?file=/src/App.js
Another idea I had: polling stops if the app is seen as not focussed, unless you turn on
refetchIntervalInBackground: true
. This is determined by the globalfocusManager
. Now you can set your own focus event handling there and set it tofocused: false
manually if you switch away to a different tab where no polling should occur. No…