question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Polling not working in background in React Native

See original GitHub issue

Intended outcome: Execute the query every 30 seconds even if the device is locked or if the app is in the background

Actual outcome: I want to execute a query every 30 seconds so I’m using pollInterval. Everything works fine, except when the application goes to the background because it stops from executing the query.

This is my query:

	const {
		loading,
		error,
		refetch,
		data
	} = useQuery(UNDELIVERED_ORDERS, {
		variables: {
			courier: userId
		},
		pollInterval: 30000,
		fetchPolicy: "network-only"
	})

How to reproduce the issue: Just use poll interval in React Native and press home or block the device

Versions

System: OS: Linux 5.0 Ubuntu 18.04.3 LTS (Bionic Beaver) Binaries: Node: 12.4.0 - ~/.nvm/versions/node/v12.4.0/bin/node Yarn: 1.19.2 - /usr/bin/yarn npm: 6.11.3 - ~/.nvm/versions/node/v12.4.0/bin/npm Browsers: Chrome: 78.0.3904.108 Firefox: 70.0.1 npmPackages: @apollo/react-hooks: ^3.0.1 => 3.0.1 apollo-boost: ^0.4.4 => 0.4.4 apollo-link-context: ^1.0.18 => 1.0.18 npmGlobalPackages: apollo: 2.18.3

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
HugoLiconVcommented, Feb 12, 2020

So does a useQuery with a pollInterval set run in the background if the user were to navigate to the home screen of the device? Or would it only run if the app is opened?

For me, it’s only running when I have the app opened

1reaction
TheEhsanSarsharcommented, Apr 3, 2020

it’s not because of apollo-client. it’s because your app is in background and not just apollo-client but all of codes stop running. you should find a way to run background task

Read more comments on GitHub >

github_iconTop Results From Across the Web

Background service in React Native - Stack Overflow
Ah ok, I misunderstood your problem initially. The first thing which comes to my mind is to do polling: push messages to queue...
Read more >
Background polling in React Native : r/reactnative - Reddit
I am developing a location based app (for both iOS and Android) in react native that needs to track the user's location every...
Read more >
Create a Secure Chat Application with Socket.IO and React
This tutorial shows you how to create a real-time chat application using JavaScript and Socket.IO.
Read more >
Polling in React using the useInterval Custom Hook
A simple example of how polling intervals used to work in React. ... the clearInterval() function is called and the interval stops running....
Read more >
Run React Native background tasks with Headless JS
In React Native, performing a task in the background might seem daunting at first. It is not as simple as writing a function...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found