@dangttp/react-native-background-service
TypeScript icon, indicating that this package has built-in type declarations

0.1.3 • Public • Published

react-native-background-service

A simple React Native library inspired by react-native-background-timer for managing background service and task

Installation

npm install @dangttp/react-native-background-service

or

yarn add @dangttp/react-native-background-service

Usage

import BackgroundService from '@dangttp/react-native-background-service';

Call addBackgroundService(callback: () => void, delay: number) when you want to loop after amount of miliseconds (even in background mode) like shown below

/** In my example I use it in my App.tsx initial useEffect */

useEffect(() => {
  BackgroundService.addBackgroundService(async () => {
    const location = await fetchLocation();
    emitLocationToSocket(location);
  }, 10000);

  return () => {
    BackgroundService.stopBackgroundService();
  };
}, []);

Call stopBackgroundService() when you discard your app like shown below

useEffect(() => {
  // Your code here

  return () => {
    BackgroundService.stopBackgroundService();
  };
}, []);

License

MIT


Made with create-react-native-library

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.1.3
    2
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.1.3
    2
  • 0.1.1
    0

Package Sidebar

Install

npm i @dangttp/react-native-background-service

Weekly Downloads

2

Version

0.1.3

License

MIT

Unpacked Size

36.8 kB

Total Files

19

Last publish

Collaborators

  • dangttp97