rn-use-background-timer
v1.0.5
Published
A custom React Native Hook that calculates the time an app spends in the inactive or background state. Ideal for handling operations when the app's state changes.
Downloads
9
Readme
Intro
Motivation
Installation
npm install @react-native-async-storage/async-storage
or
yarn add @react-native-async-storage/async-storage
then
npm install rn-use-background-timer
or
yarn add rn-use-background-timer
Usage
const App = () => {
const { duration } = useBackgroundTimer();
// or
const { duration } = useBackgroundTimer({
keepPreviousTime: true,
onError: (error) => console.error(error),
onBackground: () => console.log("App went to background"),
onActive: () => console.log("App is now active"),
});
return (
<View>
<Text>App has been in background for {duration} seconds</Text>
</View>
);
};