uselocalstorage-react-hook
v1.0.5
Published
Use local storage in react
Downloads
23
Maintainers
Readme
Uselocalstorage-React-Hook
This is an amazing package that will help you add local storage variables easily in your react app.
🛠️ Installation
- Install using npm
npm i uselocalstorage-react-hook
- Add to your project
import useLocalStorage from "uselocalstorage-react-hook";
- Start using
uselocalstorage-react-hook
const [name, setName] = useLocalStorage("name", "John Doe");
💻 Example Code
import React from "react";
import "./styles.css";
import useLocalStorage from "uselocalstorage-react-hook";
const App = () => {
const [name, setName] = useLocalStorage("name", "John Doe");
return (
<div>
<input
type="text"
value={name}
onChange={(e) => setName(e.target.value)}
/>
<h1>{name}</h1>
<p>Refresh this page, the name remains the same. 🤟</p>
</div>
);
};
export default App;
🦄 Live Demo
- https://codesandbox.io/s/uselocalstorage-react-hook-yy2nf (Intermediate 📌)
🙌 Thanks
Thanks to everyone who contributed to the development of this project.
If you enjoyed, go follow me on Twitter 💖
🛡️ License
MIT Licensed. Copyright (c) Savio Martin.