react-native-background-timer icon indicating copy to clipboard operation
react-native-background-timer copied to clipboard

BackgroundTimer.clearInterval not working

Open sankomil opened this issue 4 years ago • 1 comments

Hi, I am making a simple implementation of the background timer, just trying to console log a statement every 3 seconds. While the phrase is logged, when I call clearInterval through a button, it has no effect on the interval and the log continues. My code looks as such:

export const TestFunction = () => {

 const timeRef = BackgroundTimer.setInterval(() => {
     console.log('tac');
   }, 3000);

 return (

   <Button title="Press" onPress={()=>BackgroundTimer.clearInterval(timeref)} />
 )
}

react-native info:

System:
    OS: Windows 10 10.0.19042
    CPU: (8) x64 Intel(R) Core(TM) i7-10510U CPU @ 1.80GHz
    Memory: 5.80 GB / 15.83 GB
  Binaries:
    Node: 14.11.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.5 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 6.14.8 - C:\Program Files\nodejs\npm.CMD
    Watchman: Not Found
  SDKs:
    Android SDK:
      API Levels: 29, 30
      Build Tools: 28.0.3, 29.0.2, 30.0.3
      System Images: android-29 | Intel x86 Atom_64, android-29 | Google APIs Intel x86 Atom
      Android NDK: Not Found
    Windows SDK: Not Found
  IDEs:
    Android Studio: Version  4.1.0.0 AI-201.8743.12.41.6953283
    Visual Studio: Not Found
  Languages:
    Java: javac 15
    Python: 3.8.7
  npmPackages:
    @react-native-community/cli: Not Found
    react: ^17.0.1 => 17.0.2
    react-native: 0.63.4 => 0.63.4
    react-native-windows: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Please let me know if any further information is needed. Thanks.

sankomil avatar Jun 04 '21 06:06 sankomil

Hi, try this : BackgroundTimer.clearInterval(timeref.current)

jsellam avatar Jun 30 '21 13:06 jsellam