A react native hook to run code when your app is launched, focused and blurred.
yarn add @pachun/react-native-use-app-lifecycleIn 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 AppTest driving code is nice. Writing tests for ref code sucks. Use this package to avoid TDDing ref code and improve the readability of your tests a little bit.
I use this package to check for and download Over-The-Air (OTA) expo updates.
import { renderRouter, act } from "expo-router/testing-library"
import useAppLifecycle from "@pachun/react-native-use-app-lifecycle"
jest.mock("@pachun/react-native-use-app-lifecycle", () => ({
__esModule: true,
default: jest.fn(),
}))
describe("foregrounding the application", () => {
it("does stuff", async () => {
let triggerAppForeground
jest.mocked(useAppLifecycle).mockImplementation(({ onFocus }) => {
triggerAppForeground = onFocus
})
renderRouter("src/app", { initialUrl: "/" })
await act(() => triggerAppForeground!)
// expect stuff
})
})PRs are exciting 🤟 Bump the version number in package.json and open one.
- 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).