react-native-lifecycle
TypeScript icon, indicating that this package has built-in type declarations

2.1.2 • Public • Published

React Native Lifecycle

GitHub license Latest Version on NPM npm build status

简体中文

Install

yarn add react-native-lifecycle

Peer Dependencies

yarn add @react-navigation/native # >= 5.7.0 or >= 6.0.0

Support

package name version react-native version
react-native-lifecycle 2.0.0+ 0.65.0+
react-native-lifecycle 1.2.4+ 0.59.0+

Usage

Example

Global Hooks
import { useAppActive, useAppInactive } from 'react-native-lifecycle';

export default function App() {
  // Called when the application switches from the background to the foreground
  useAppActive(() => {});

  // Called when the application switches from the foreground to background
  useAppInactive(() => {});
}
Page/Screen Hooks
import {
  useMount,
  useShow,
  useHide,
  useUnmount,
  useResize,
} from 'react-native-lifecycle';

export default function Page() {
  // Called when the component is mounted
  useMount(() => {});

  // Called when the page is displayed, or when the application switches from the background to the foreground
  useShow(() => {});

  // Called when the page is hidden, or when the application switches from the foreground to the background
  useHide(() => {});

  // Called when the component is unmounted
  useUnmount(() => {});

  // Called after the page window resize
  useResize(() => {});
}

Readme

Keywords

none

Package Sidebar

Install

npm i react-native-lifecycle

Weekly Downloads

1

Version

2.1.2

License

MIT

Unpacked Size

19.2 kB

Total Files

31

Last publish

Collaborators

  • chooin