Licence
MIT
Version
0.3.0
Deps
1
Size
242 kB
Vulns
0
Weekly
0
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