3.1.10 • Published 5 months ago

uselocalstroage v3.1.10

Weekly downloads
-
License
ISC
Repository
-
Last release
5 months ago

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>
  );
}
3.1.10

5 months ago

3.1.9

5 months ago

3.1.8

5 months ago

3.1.7

5 months ago

3.1.6

5 months ago

3.1.5

5 months ago

3.1.4

5 months ago

3.1.3

5 months ago

3.1.2

5 months ago

3.1.1

5 months ago

3.1.0

5 months ago

3.0.0

5 months ago

2.0.0

5 months ago

1.0.0

5 months ago