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

npmnpm install onetime
pnpmpnpm add onetime

Methods

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.

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.