API Reference
onetime
Ensure a function is called only once, caching the first result for reuse.
Official Documentation ↗CompatibilityThis documentation covers version
v7.0.0. Check the official docs for the latest API surface.Installation
npm
npm install onetimepnpm
pnpm add onetimeMethods
No methods match this filter.
onetime is ensure a function is called only once, caching the first result for reuse.
Key Features
- data-fetching: Designed for data fetching scenarios with a focused API surface.
Installation
npm install onetime
Usage
API reference evidence
Fetched from official sources on 2026-11-08T18:22:00+08:00 via WebFetch https://raw.githubusercontent.com/sindresorhus/onetime/main/index.d.ts.
onetime.once→ signature from https://raw.githubusercontent.com/sindresorhus/onetime/main/index.d.ts; official text: “<ArgumentsType extends unknown[], ReturnType>( fn: (…arguments_: ArgumentsType) => ReturnType, options?: Options ): OnetimeFunction<ArgumentsType, ReturnType>;”
FAQ
- What is the difference between debounce and throttle?
- Debounce delays until activity stops for wait ms; throttle guarantees at most one invocation per wait window.
- Does onetime support leading and trailing edges?
- Yes, pass { leading: true, trailing: false } to control when the function fires.
- Is onetime safe for use in React effects?
- Yes, but cancel pending calls on cleanup to avoid setState after unmount.
Report a problem with this API docOpens a pre-filled issue on GitHub.