2.0.4 • Published 4 years ago

react-storage-hook v2.0.4

Weekly downloads
9
License
MIT
Repository
github
Last release
4 years ago

react-storage-hook

Javascript library for synchronously managing localStorage / sessionStorage. Typescript types included.

demo.gif

Installation

yarn add react-storage-hook

Usage

See also live example with sourcemaps and the local copy.

import { useStorage } from 'react-storage-hook';

const SavedCheckbox = () => {
  const [checked, setChecked] = useStorage('saved-checkbox-checked', {
    placeholder: false,
    // storageArea: sessionStorage // to use session storage instead
  })

  const onChange = e => setChecked(e.target.checked);

  return <input {...{
    checked,
    onChange,
    type: "checkbox"
  }}>
}

The checked state will be stored and synchronized between instances of the page.

The typescript types are authoratative for API scheme.

2.0.4

4 years ago

2.0.3

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago