0.1.0 • Published 3 years ago

cache-hook v0.1.0

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

Use Cache

A React hook for caching data globally.

About

React's useMemo is great, but it only caches the result for the lifetime of a single component. This hook ensures that an expensive operation will only be performed once for the same input within the lifetime of a whole page load.

Install

# yarn
yarn add cache-hook

# npm
npm install --save cache-hook

Usage

import createCache from 'cache-hook';

let useCache = createCache(data => {
  // perform expensive operation
  return result;
})

let Component = () => {
  let cached = useCache('input');

  return (
    <div>
      Result: {cached}
    </div>
  )
}

License

MIT © Tobias Herber

Made by Varld