@drobs/local-storage-react
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i @drobs/local-storage-react

Weekly Downloads

0

Version

1.2.0

License

ISC

Unpacked Size

7.12 kB

Total Files

7

Last publish

Collaborators

  • ddrobecq