@usefy/use-mount
v0.25.1
Published
A React hook that runs a callback once when the component mounts
Maintainers
Readme
Overview
useMount is part of the @usefy ecosystem — a collection of production-ready, TypeScript-first, SSR-safe React hooks. Runs a callback once when the component mounts.
Features
- Mount-only — clear intent, runs once
- Optional cleanup — return a function to run on unmount
- Readable — an alias for
useEffect(fn, []) - TypeScript-first — full type inference and exported types
- Tiny & tree-shakeable — zero dependencies, published as its own package
Installation
# npm
npm install @usefy/use-mount
# yarn
yarn add @usefy/use-mount
# pnpm
pnpm add @usefy/use-mountRequires React 18 or 19 (peerDependencies: "react": "^18.0.0 || ^19.0.0").
Quick Start
import { useMount } from "@usefy/use-mount";
useMount(() => {
analytics.page();
return () => cleanup();
});API
useMount(effect) — runs effect once on mount; an optional returned function runs on unmount.
Testing
📊 View Detailed Coverage Report (GitHub Pages) — 3 tests, 100% statement coverage.
License
MIT © mirunamu
This package is part of the usefy monorepo.
