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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@jsxtools/react-hooks

v1.1.6

Published

A tree-shakable collection of hooks for React

Readme

react-hooks

react-hooks is a tree-shakable collection of hooks for React.

It is 541 bytes (262 gzipped).

useDebouncedState

useDebouncedState provides a state and setter that throttle updates coming in rapid succession.

import { useDebouncedState } from '@jsxtools/react-hooks';

function Component() {
  // successive updates to `searchTerm` to will be deferred by 400 milliseconds
  const [searchTerm, setSearchTerm] = useDebouncedState(initialState, 400);
  const onSearchTermInput = event => setSearchTerm(event.target.value);

  return (
    <p>
      <label htmlFor="q">Search</label>
      <input id="q" name="q" defaultValue="" onInput={onSearchTermInput}>
    </p>
  )
}

useEqualState

useEqualState provides a state and setter that check for shallow or deep changes.

import { useEqualState } from '@jsxtools/react-hooks';

function Component() {
  // shallow updates to `formData` will not trigger re-renders
  const [formData, setFormData] = useEqualState({ givenName: 'Jonathan', familyName: 'Neal' });
  const onGivenNameInput = event => setFormData({ ...formData, givenName: event.target.value });
  const onFamilyNameInput = event => setFormData({ ...formData, familyName: event.target.value });

  return (
    <>
      <p>
        <label htmlFor="gn">Given Name</label>
        <input id="gn" defaultValue={formData.givenName} onInput={onGivenNameInput} />
      </p>
      <p>
        <label htmlFor="fn">Family Name</label>
        <input id="fn" defaultValue={formData.familyName} onInput={onFamilyNameInput} />
      </p>
    </>
  );
}

useLocalStorage

useLocalStorage provides a state and setter bound to Local Storage.

import { useLocalStorage } from '@jsxtools/react-hooks';

function Component() {
  // the `value` of `counter` will persist after the browser is refreshed
  const [value, setValue] = useLocalStorage('counter', 0);
  const inc = setValue.bind(null, value + 1);
  const dec = setValue.bind(null, value - 1);

  return (
    <p>
      <span>Value is "{value}".</span>
      <button aria-label="decrement value" onClick={dec}>-</button>
      <button aria-label="increment value" onClick={inc}>+</button>
    </p>
  );
}

usePromise

usePromise provides a state and settled value of a Promise.

import { usePromise } from '@jsxtools/react-hooks';

function Component () {
  // the `state` is "pending", "fulfilled", or "rejected"
  // the `settledValue` is the fulfilled or rejected value
  const [ state, settledValue ] = usePromise(async () => {
    const response = await fetch(URL);
    const json = await response.json();

    return json;
  });

  return state === 'pending'
    ? 'Loading'
  : JSON.stringify(settledValue);
}

Installation

npm install @jsxtools/react-hooks

Usage

import reactHooks from '@jsxtools/react-hooks';

reactHooks();