FluentUI Compat

Home > @cascadiacollections/fluentui-compat > createMemoizer

createMemoizer() function

Creates a highly optimized memoizer for single-argument functions where the argument is an object or function. Uses WeakMap for automatic memory management.

This is ideal for functions that transform objects/functions and need automatic cleanup when the source objects are garbage collected.

Signature:

export declare function createMemoizer<F extends (input: any) => any>(getValue: F): F;

Parameters

Parameter

Type

Description

getValue

F

Function to memoize (must accept single object/function argument)

Returns:

F

Memoized version of the function with WeakMap-based caching

Example

const expensiveTransform = createMemoizer((obj: SomeObject) => ({
  ...obj,
  computed: performExpensiveComputation(obj)
}));

// Subsequent calls with same object reference return cached result
const result1 = expensiveTransform(myObj);
const result2 = expensiveTransform(myObj); // Returns cached result
  • Edit this page
In this article
Back to top FluentUI React complimentary components and utilities focused on render performance