use-localforage
v0.3.0
Published
React hooks for localforage
Downloads
4
Readme
use-localforage
React hooks to fetch and keep data in-sync in localforage.
Requires React
^16.7.0-alpha.0
.
// @flow
import useLocalforage from 'use-localforage';
export default function Landing(props: {}): React$Node {
const [cachedPosts, setCachedPosts, err] = useLocalforage('posts');
React.useEffect(() => {
if (!cachedPosts) {
const res = await unfetch(`${endpoint}/posts`);
const { posts } = await res.json();
setCachedPosts(posts);
}
});
return (
<React.Fragment>
<Posts posts={cachedPosts} />
</React.Fragment>
);
}
install
yarn add use-localforage
license
MIT © Kevin Donahue