ease-hooks
v1.1.0
Published
easy to use hook collection for react
Downloads
17
Readme
Install
npm install ease-hooks
# or
yarn add ease-hooks
useCache
useCache expect 4 parameter:
- cacheName(required): unique name for identifying data.
- getter(required): this function expect to return a
Promise
like. - level: 1 for memory cache, 2 for sessionStorage, 3 for localStorage.
- expireDays: for how many day data will be expired.
import {useCache} from "ease-hooks";
function Component() {
const [data, update, clear ] = useCache("CACHE_NAME", () => {
return Promise.resolve(SomeData)
}, 0, 30);
clear() // clear saved data, at next time it runs, data will be reloaded.
update(data) // update saved data.
// some other code
}