/memo-deps

Memo with Dependencies, same API as React.useMemo

Primary LanguageTypeScriptApache License 2.0Apache-2.0

memo-deps

Coverage Status npm version

Memo with Dependencies. Inspired from React.useMemo. This can be used outside of React components without hooks.

Usage

import { memo } from 'memo-deps';

function expensive(arg1, arg2) {
    // 
}

const memoized = memo(expensive);

const dep1 = { a: 1 };
const dep2 = [ 4 ];

let result1 = memoized([arg1, arg2], [dep1, dep2]);
let result2 = memoized([arg3, arg4], [dep1, dep2]); // `expensive` is not called again, result2 === result1.
let result3 = memoized([arg3, arg4], [dep3, dep4]); // `expensive` is called again.