npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

use-storage-hooks

v0.1.4

Published

A lightweight React library that provides hooks for interacting with localStorage and sessionStorage. Simplifies state management using browser storage with clean APIs.

Readme

use-storage-hooks

use-storage-hooks is a lightweight, easy-to-use library that provides React hooks for working with browser storage (localStorage and sessionStorage). It simplifies state management by enabling seamless integration of persistent storage into your React components.

Why use use-storage-hooks?

This library provides a hassle-free solution for managing state persistence across sessions. Whether you need to store user preferences or temporary data, use-storage-hooks helps you integrate browser storage without repetitive boilerplate code.

Installation

To install the library, use npm or yarn:

npm install use-storage-hooks

or

yarn add use-storage-hooks

Hooks

useLocalStorage

This hook allows you to manage state that is synchronized with localStorage.

Usage

import { useLocalStorage } from 'use-storage-hooks';

const [value, setValue] = useLocalStorage<number>('key');

Parameters

  • key (string): The key under which the value is stored in localStorage.

Returns

  • value (T | undefined): The current value associated with the key. It returns the value of the generic type T or undefined.
  • setValue (function): A function to update the value. It accepts a value of type T or undefined. If undefined is passed, the value will be removed from localStorage.

useSessionStorage

This hook allows you to manage state that is synchronized with sessionStorage.

Usage

import { useSessionStorage } from 'use-storage-hooks';

const [value, setValue] = useSessionStorage<number>('key');

Parameters

  • key (string): The key under which the value is stored in sessionStorage.

Returns

  • value (T | undefined): The current value associated with the key. It returns the value of the generic type T or undefined.
  • setValue (function): A function to update the value. It accepts a value of type T or undefined. If undefined is passed, the value will be removed from sessionStorage.

Example with useLocalStorage and useSessionStorage

import React from 'react';
import { useLocalStorage, useSessionStorage } from 'use-storage-hooks';

function ComponentA() {
    const [localValue, setLocalValue] = useLocalStorage<number>('local-key');
    const [sessionValue, setSessionValue] = useSessionStorage<number>('session-key');

    return (
        <div>
            <p>Local Storage Value: {localValue}</p>
            <button onClick={() => setLocalValue(Math.random())}>Generate Random Local Number</button>
            <button onClick={() => setLocalValue(undefined)}>Remove Local Value</button>

            <p>Session Storage Value: {sessionValue}</p>
            <button onClick={() => setSessionValue(Math.random())}>Generate Random Session Number</button>
            <button onClick={() => setSessionValue(undefined)}>Remove Session Value</button>
        </div>
    );
}

function ComponentB() {
    const [localValue] = useLocalStorage<number>('local-key');
    const [sessionValue] = useSessionStorage<number>('session-key');

    return (
        <div>
            <p>Local Storage Value: {localValue}</p>
            <p>Session Storage Value: {sessionValue}</p>
        </div>
    );
}

function App() {
    return (
        <div>
            <ComponentA />
            <ComponentB />
        </div>
    );
}

export default App;

In this example, ComponentA and ComponentB share the same keys for both localStorage ('local-key') and sessionStorage ('session-key'). When the values are updated in ComponentA, they are immediately reflected in ComponentB. The "Generate Random Local Number" and "Generate Random Session Number" buttons set new random numbers, and the "Remove" buttons remove the values from localStorage and sessionStorage respectively.

Both hooks use generics to allow you to specify the type of the stored value. By default, the type is unknown, but you can specify a different type when using the hooks.

Example with Generics

import { useLocalStorage } from 'use-storage-hooks';

const [value, setValue] = useLocalStorage<number>('key');

In this example, value will be of type number and setValue will accept a value of type number or undefined.

License

MIT