Skip to content

React Native Setting a timer for a long period of time warning #1259

@vikrantnegi

Description

@vikrantnegi

Describe the bug
I'm using react query in react native to fetch the geolocation coordinates. It iseems to be working fine but giving a warning in the console Setting a timer for a long period of time.

To Reproduce
Steps to reproduce the behavior:

  1. Create React Native CLI Project
  2. Install react-native-geolocation-service
  3. create a react query for fetching location

Expected behavior
When I try to mimic the react query using custom hooks it doesn't give the timer warning.

Smartphone (please complete the following information):

  • Device: Android emulator, Pixel_2_API_29
  • OS: macOS Catalina
  • "react": "16.13.1",
  • "react-native": "0.63.3",
  • "react-query": "^2.26.1"

Code:

async function getPosition() {
  const hasLocationPermission = await checkLocationPermission();

  if (!hasLocationPermission) {
    return;
  }

  return new Promise((res, rej) => {
    Geolocation.getCurrentPosition(res, rej);
  });
}

const App = () => {
  const info = useQuery('pos', getPosition);
  console.log({info});
}

Warning:

Setting a timer for a long period of time, i.e. multiple minutes, is a performance and correctness issue on Android as it keeps the timer module awake, and timers can only be called when the app is in the foreground. See https://github.com/facebook/react-native/issues/12981 for more info.
(Saw setTimeout with duration 300000ms) 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions