react-native-lifecycle
v2.1.2
Published
React Native Lifecycle
Downloads
72
Readme
React Native Lifecycle
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
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(() => {});
}