0.3.0 • Published 5 years ago

use-localforage v0.3.0

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

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

0.3.0

5 years ago

0.2.0

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago