3.1.10 • Published 2 years ago

uselocalstroage v3.1.10

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years 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

2 years ago

3.1.9

2 years ago

3.1.8

2 years ago

3.1.7

2 years ago

3.1.6

2 years ago

3.1.5

2 years ago

3.1.4

2 years ago

3.1.3

2 years ago

3.1.2

2 years ago

3.1.1

2 years ago

3.1.0

2 years ago

3.0.0

2 years ago

2.0.0

2 years ago

1.0.0

2 years ago