@sjblurton/use-storage
TypeScript icon, indicating that this package has built-in type declarations

0.1.3 • Public • Published

useStorage

useStorage hook stores the data in local, or session storage. It takes a key as a string argument, and a default value as a string. The hook will search the storage the key in storage for a value and return if it there is one, otherwise it will use the default value.

If you want to store an object then use JON.stringify, and JON.parse to send a string to the hook.

return a tuple of [ string, setState function, and a remove function ].

To install...

mpn i @sjblurton/use-storage

yarn add @sjblurton/use-storage

To import...

import { useLocalStorage, useSessionStorage } from "../hooks/use-storage"

To call the hook...

const [name, setName, removeName] = useSessionStorage("name", "foo")

const [age, setAge, removeAge] = useLocalStorage("age", "40")

Links

GitHub: https://github.com/sjblurton/use-storage
NPM: https://www.npmjs.com/package/@sjblurton/use-storage

Package Sidebar

Install

npm i @sjblurton/use-storage

Weekly Downloads

1

Version

0.1.3

License

MIT

Unpacked Size

13.5 kB

Total Files

15

Last publish

Collaborators

  • sjblurton