Skip to content

A react native hook to run code when your app is launched, focused and blurred.

License

Notifications You must be signed in to change notification settings

pachun/react-native-use-app-lifecycle

Repository files navigation

npm version cov

useAppLifecycle

A react native hook to run code when your app is launched, focused and blurred.

Install

yarn add @pachun/react-native-use-app-lifecycle

Usage

In your topmost-level component:

import useAppLifecycle from "@pachun/react-native-use-app-lifecycle"

const App = () => {
  useAppLifecycle({
    onLaunch: () => console.log("launch"),
    onFocus: () => console.log("focus"),
    onBlur: () => console.log("blur"),
  })

  return <></>
}

export default App

Motivation

I've been copying and pasting this code into all my RN projects for a long time. Usually, I use it to check for and download Over-The-Air (OTA) expo updates.

Contributing

PRs are exciting 🤟 Bump the version number in package.json and open some.

  • Please do not submit AI generated pull requests.
  • Please keep coverage at or above where it is when you clone the repo (yarn test --collectCoverage).

About

A react native hook to run code when your app is launched, focused and blurred.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published