Skip to content

chooin/react-native-lifecycle

Repository files navigation

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 page or 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 page or component is unmounted
  useUnmount(() => {});

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

About

React Native Lifecycle

Topics

Resources

License

Stars

Watchers

Forks

Contributors 2

  •  
  •  
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy