JSFiddle - React, Tailwind, and code Playground

JavaScript

function memoize(func) {
  const cache = new Map();
  return function(...args) {
    // Use first argument as key
    const key = args[0];
    if (cache.has(key)) {
      console.log('cache hit');
      return cache.get(key);
    }
    console.log('cache miss');
    const val = func.apply(this, arguments);
    cache.set(key, val);
    return val;
  };
}