Giter Site home page Giter Site logo

vincentbollaert / react-use-idb Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kigiri/react-use-idb

0.0 2.0 0.0 12 KB

React side-effect hook that manages a single indexDB item.

Home Page: https://www.npmjs.com/package/react-use-idb

License: MIT License

JavaScript 84.06% HTML 15.94%

react-use-idb's Introduction

react-use-idb (useIdb)

React side-effect hook that manages a single indexDB item.

A drop-in remplacement over useLocalStorage.

Why ?

LocalStorage is synchronous and as such, has performances issues

LocalStorage is also limited, only storing strings and does not provide a default mechanisme for serializing / deserializing your data.

Instead, we can rely on indexDB for structural cloning.

Usage

import { useIdb } from 'react-use-idb'

const Demo = () => {
  const [value, setValue] = useIdb('my-key', 'foo')

  return (
    <div>
      <div>Value: {value}</div>
      <button onClick={() => setValue('bar')}>bar</button>
      <button onClick={() => setValue('baz')}>baz</button>
    </div>
  )
}

Reference

useIdb(key)
useIdb(key, initialValue)
  • key โ€” indexDB item key to manage.
  • initialValue โ€” initial value to set, if value in the indexDB item is empty.

Inspired by idb-keyval

react-use-idb's People

Contributors

kigiri avatar ecancino avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.