https://github.com/amrlabib/react-native-appstate-hook
React Native appSate hook
https://github.com/amrlabib/react-native-appstate-hook
android appstate component function-components hooks ios react react-hook react-hooks react-native
Last synced: 10 days ago
JSON representation
React Native appSate hook
- Host: GitHub
- URL: https://github.com/amrlabib/react-native-appstate-hook
- Owner: amrlabib
- License: mit
- Created: 2019-02-16T21:57:28.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2022-05-06T10:21:52.000Z (over 3 years ago)
- Last Synced: 2025-09-18T00:50:43.454Z (4 months ago)
- Topics: android, appstate, component, function-components, hooks, ios, react, react-hook, react-hooks, react-native
- Homepage: https://www.npmjs.com/package/react-native-appstate-hook
- Size: 18.6 KB
- Stars: 120
- Watchers: 2
- Forks: 22
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
## react-native-appstate-hook
React Native appState hook is a custom [react hook](https://reactjs.org/docs/hooks-intro.html), 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
```javascript
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 (
App State is: {appState}
);
}
```
---
## Settings
| key | Type | Required | Description |
| --- | --- | --- | ---- |
| onChange | Function | No | callback function to be executed once `appState` is changed |
| onForeground | Function | No | callback function to be executed once app go to foreground |
| onBackground | Function | No | callback function to be executed once app go to background |
---
## Values
| key | Type | Description |
| --- | --- | ---- |
| appState | string | app state it can be one of the following values `active`, `inactive`, or `background` |