once es-toolkit
Creates a new function that limits a function to be executed only once.
Usage
once(func)
Use once when you want to limit a function to be executed only once. Subsequent calls will return the result from the first call.
This is useful for logic that should only be executed once, such as initialization functions or event handlers. It prevents duplicate execution and ensures consistent results.
You can also use it with functions that take arguments.
Parameters
The function to restrict to a single execution.
Returns
Returns a new function that caches the result after the first call and returns the same result for subsequent calls.
Source: es-toolkit
Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.