@drobs/local-storage-react
v1.2.0
Published
react local storage hook
Downloads
86
Readme
Drobs Local Storage React
This package proposes a react hook to read and set value from/to local storage
Installation
npm install @drobs/local-storage-react
Use
Import package in your react app Import useLocalStorage from 'drobs-local-storage-react'; Add a hook in your component with useLocalStorage (keyName, defaultValue) const [name, setName] = useLocalStorage('name', 'John Doe');
--- example ---
'use client';
import Image from "next/image";
import styles from "./page.module.css";
import useLocalStorage from 'drobs-local-storage-react';
export default function Home() {
const [name, setName] = useLocalStorage('name', 'John Doe');
return (
<div className={styles.container}>
<h1>Hello, {name}!</h1>
<input
type="text"
value={name}
onChange={(e) => setName(e.target.value)}
/>
<Image
src="/vercel.svg"
alt="Vercel Logo"
width={72}
height={16}
/>
</div>
);
}
Contribute
GitHub Repository
GitHub
Compile
npm run build