Skip to content

memo

Like the memoize function, but simpler and smaller.

The cache key will be generated by joining all the args together and the cache will never expire.

Usage

js
import { memo } from '@studiometa/js-toolkit/utils';

function heavyFunction(a, b) {
  return a.replace(/foo/g, b);
}

const memoHeavyFunction = memo(heavyFunction);

memoHeavyFunction('foo', 'bar'); // bar

Parameters

  • fn (Function): the function to cache

Return value

This function returns a new function which will cache the first function results.

MIT Licensed