Skip to content

once

Create a function that runs at most once, no matter how many times it's called. If it was already called before, returns the result from the first call. This is a lighter version of `memo()`. To allow your `once`-wrapped function to be called again, see the `once.reset` function.

Usage

const fn = once(() => Math.random());
fn(); // 0.5
fn(); // 0.5

Installation

Terminal window
npx atmx add helper once