Getting Started
Start your React project with toolchains like Create-React-App, NextJS, or GatsbyJS. Or use a bundler like Parcel and install react and react-dom yourself. Learn more from the official docs.
npx create-react-app my-project && cd my-projectInstallation#
Once you have your React project started, install the kantan-hooks package by running the command:
npm install kantan-hooksOr do it with yarn:
yarn add kantan-hooksNext, import the hook that you need. For example, the useLocalStorage hook helps you to manage a state that will be stored by the LocalStorage API.
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> );}