0.1.3 • Published 2 years ago
@sjblurton/use-storage v0.1.3
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