use-react-native-app-state
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

use-appstate

This module makes it easy to use React Native's AppState with React Hooks.

Installation

yarn add use-appstate

Usage

useAppState

import { useAppState } from 'use-appstate';
 
function Component(props) {
    // Possible values: "active", "background", "inactive" (iOS only)
    const appState = useAppState();
    // ...
}

useAppStateChange

import { useAppStateChange } from 'use-appstate';
 
function Component(props) {
    useAppStateChange(
        (status: AppStateStatus) => alert('App state changed: ' + status),
        // triggers to update the callback
        [props.updateCallbackWhenThisPropsChanges],
    );
    // ...
}

useAppStateChangedTo

import { useAppStateChangedTo } from 'use-appstate';
 
function Component(props) {
    useAppStateChangedTo(
        // Possible values: "active", "background", "inactive" (iOS only)
        'active',
        () => alert('App became active'),
        // triggers to update the callback
        [props.updateCallbackWhenThisPropsChanges],
    );
    // ...
}

Readme

Keywords

none

Package Sidebar

Install

npm i use-react-native-app-state

Weekly Downloads

125

Version

0.0.2

License

none

Unpacked Size

5.27 kB

Total Files

8

Last publish

Collaborators

  • fant