Skip to content

varld/cache-hook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

A react hook for caching data

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published