1.0.6 • Published 3 years ago

react-native-appstate-hook v1.0.6

Weekly downloads
2,795
License
ISC
Repository
github
Last release
3 years ago

react-native-appstate-hook

React Native appState hook is a custom react hook, built to handle iOS or Android appState in your react component

Note:

React hooks is available from react version 16.8.0 and react native version 0.59.0


Setup

yarn add react-native-appstate-hook

OR

npm install --save react-native-appstate-hook


Example

import React from 'react';
import { Text, View } from 'react-native';
import useAppState from 'react-native-appstate-hook';


export default function App() {
  const { appState } = useAppState({
    onChange: (newAppState) => console.warn('App state changed to ', newAppState),
    onForeground: () => console.warn('App went to Foreground'),
    onBackground: () => console.warn('App went to background'),
  });

  return (
    <View style={{textAlign: 'center', backgroundColor :'white', flex: 1, justifyContent: 'center'}}>
      <Text>App State is: {appState}</Text>
    </View>
  );
}

Settings

keyTypeRequiredDescription
onChangeFunctionNocallback function to be executed once appState is changed
onForegroundFunctionNocallback function to be executed once app go to foreground
onBackgroundFunctionNocallback function to be executed once app go to background

Values

keyTypeDescription
appStatestringapp state it can be one of the following values active, inactive, or background