uselocalstroage
TypeScript icon, indicating that this package has built-in type declarations

3.1.10 • Public • Published

uselocalstroage

A simple React hook for interacting with localStorage.

Features

  • Easy Integration: Quickly integrate local storage functionality into your React components.

  • Type-Safe Retrieval: Use generics to ensure type safety when retrieving stored values.

  • Flexible Storage: Store and retrieve both simple data types (strings, numbers) and complex objects.

  • Lightweight: Keep your dependencies minimal with a small, standalone package.

Installation

npm install uselocalstroage

Quickstart

import useLocalStorage from "uselocalstroage";

function App() {
  // Initialize the useLocalStorage hook
  const { getItem, setItem, delItem } = useLocalStorage();

  // Example of using the hook in a React component
  const handleSetItem = () => {
    const data = { example: "value" };
    setItem("exampleKey", data);
  };

  const handleGetItem = () => {
    const data = getItem("exampleKey");
    console.log("Retrieved data:", data);
  };

  const handleDeleteItem = () => {
    delItem("exampleKey");
  };

  return (
    <div>
      <button onClick={handleSetItem}>Set Item</button>
      <button onClick={handleGetItem}>Get Item</button>
      <button onClick={handleDeleteItem}>Delete Item</button>
    </div>
  );
}

Dependencies (0)

    Dev Dependencies (6)

    Package Sidebar

    Install

    npm i uselocalstroage

    Weekly Downloads

    1

    Version

    3.1.10

    License

    ISC

    Unpacked Size

    3.96 kB

    Total Files

    6

    Last publish

    Collaborators

    • sridhar-c-25