react-recipes
Version:
A React Hooks utility library containing popular customized hooks
35 lines (26 loc) • 741 B
Markdown
and set values into localStorage
- `key: String`: A unique key to be stored in localStorage
- `initialValue: String`: Value to be used the first time for localStorage
- `storedValue: String`: Value in localStorage
- `setValue: Function`: Set a new value to localStorage
```js
import { useLocalStorage } from "react-recipes";
function App() {
// Similar to useState but first arg is key to the value in local storage.
const [name, setName] = useLocalStorage("name", "Bob");
return (
<div>
<input
type="text"
placeholder="Enter your name"
value={name}
onChange={e => setName(e.target.value)}
/>
</div>
);
}
```
Store