Skip to content

memo

The memo() function evaluates a function only once then memorizes the result. Subsequent calls return the same value without recalculation.

Interactive example

Syntax

typescript
interface Memoized<
	GenericInput extends unknown
> {
	readonly input: GenericInput;
}

function memo<
	GenericOutput extends AnyValue
>(
	theFunction: () => GenericOutput
): Memoized<GenericOutput>;

Parameters

  • theFunction : Function evaluated only once to produce the memorized value.

Return value

A Memoized object with the input property containing the single result.

See also

Released under the MIT license.