rna

react-native-appstate-hook

React Native appSate hook

Showing:

Popularity

Downloads/wk

4.1K

GitHub Stars

82

Maintenance

Last Commit

4d ago

Contributors

6

Package

Dependencies

0

License

ISC

Type Definitions

Tree-Shakeable

No?

Categories

Readme

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

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100