Kantan-Hooks is a lightweight React Hooks library. The project is still work-in-progress, and the Documentation can be found here.
Run the following command
npm install kantan-hooks
Or do it with yarn:
yarn add kantan-hooks
Next, import the hook that you need. Learn more in the documentation.
import { useLocalStorage } from "kantan-hooks";
export default function LocalStorage() {
const [theme, setTheme] = useLocalStorage("dark", "theme");
const newTheme = theme === "dark" ? "light" : "dark";
return (
<div>
<h1>current theme {theme}</h1>
<button onClick={() => setTheme(newTheme)}>change Theme</button>
<button onClick={() => window.location.reload()}>
Refresh window and check if your state persists!
</button>
</div>
);
}