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

react-callback-hooks

v0.3.1

Published

React hooks that react to events with callbacks.

Readme

react-callback-hooks

A collection of lightweight, type-safe React hooks focused on event handling, side-effects, and callback-driven patterns.

npm version license bundle size TypeScript

Features

  • Lightweight & Tree-shakeable: Import only what you need.
  • Strictly Typed: Written in TypeScript with complete type definitions.
  • SSR & Modern React: Compatible with React 18+ and React 19.
  • Callback-Driven: Ergonomic APIs designed around explicit callback triggers and lifecycle control.

Installation

# npm
npm install react-callback-hooks

# pnpm
pnpm add react-callback-hooks

# yarn
yarn add react-callback-hooks

# bun
bun add react-callback-hooks

Demos

1. useDebounce

Debounce user input or asynchronous operations with immediate state feedback and debounced execution.

import React from 'react'
import { useDebounce } from 'react-callback-hooks'

export function SearchComponent() {
  const [debouncedQuery, setQuery, immediateQuery] = useDebounce<string>(
    (value) => {
      console.log('Fetching search results for:', value)
    },
    500
  )

  return (
    <div>
      <input
        type="text"
        placeholder="Type to search..."
        value={immediateQuery ?? ''}
        onChange={(e) => setQuery(e.target.value)}
      />
      <p>Immediate: {immediateQuery}</p>
      <p>Debounced: {debouncedQuery}</p>
    </div>
  )
}

2. useClickOutside

Trigger a callback when a click or touch event occurs outside the target element.

import React, { useState } from 'react'
import { useClickOutside } from 'react-callback-hooks'

export function DropdownMenu() {
  const [isOpen, setIsOpen] = useState(false)
  const menuRef = useClickOutside<HTMLDivElement>(() => {
    setIsOpen(false)
  })

  return (
    <div>
      <button onClick={() => setIsOpen((prev) => !prev)}>
        Toggle Menu
      </button>

      {isOpen && (
        <div
          ref={menuRef}
          style={{
            border: '1px solid #ccc',
            padding: '1rem',
            marginTop: '0.5rem'
          }}
        >
          <p>Dropdown Content</p>
          <p>Click anywhere outside this box to close.</p>
        </div>
      )}
    </div>
  )
}

Available Hooks

| Hook | Description | | :--- | :--- | | useDebounce | Debounces value changes and invokes a callback after delay | | useClickOutside | Detects clicks and touches outside a referenced element | | useKeyDown | Listens for specific key combinations and keyboard events | | useKeyUp | Handles keyboard key release events | | useLocalStorage | Synchronizes state with browser localStorage and storage events | | useCookie | Synchronizes state with browser cookies with add, update, remove, and removeAll methods | | useMediaQuery | Subscribes to responsive CSS media queries | | useIntersectionObserver | Observes element visibility and viewport intersection | | useNetworkState | Monitors online/offline network connectivity status | | useBattery | Tracks battery status and charging level via Web Battery API | | useIdle | Detects user inactivity after a specified duration | | useWindowSize | Tracks window dimensions and resize events | | useCache | In-memory key-value cache with invalidation hooks | | useQuery | Async data fetching lifecycle with status callbacks | | useMutation | Async mutation execution with success/error handlers | | useWebSocket | WebSocket connection management with event dispatching |

License

MIT