You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

10 lines
176 B

  1. export default function memoize(fn) {
  2. const cache = {};
  3. return arg => {
  4. if (cache[arg] === undefined) {
  5. cache[arg] = fn(arg);
  6. }
  7. return cache[arg];
  8. };
  9. }