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

@hp-hooks/react

v0.2.1

Published

A collection of reusable, type-safe hooks

Readme

@hp-hooks/react

React TypeScript Vite+ pnpm

A collection of reusable, type-safe React hooks built with TypeScript.

Installation

npm install @hp-hooks/react

Or:

pnpm add @hp-hooks/react

Requirements: React 18 or 19.

Available Hooks

| Hook | Description | | --------------- | ---------------------------------------------------------------- | | useBattery | Subscribe to the device battery state when the browser allows it | | useMediaQuery | Subscribe to CSS media query matches using native browser APIs |

Usage

useBattery

useBattery reads the browser's Battery Status API and updates when the battery level, charging state, or time estimates change.

import { useBattery } from '@hp-hooks/react'

export function BatteryIndicator() {
  const battery = useBattery()

  if (battery.loading) {
    return <p>Reading battery status…</p>
  }

  if (!battery.supported || battery.level === null) {
    return <p>Battery status is unavailable.</p>
  }

  const percentage = Math.round(battery.level * 100)

  return (
    <p>
      {battery.charging ? 'Charging' : 'On battery'} · {percentage}%
    </p>
  )
}

The hook returns a BatteryState object:

| Property | Type | Description | | ----------------- | ----------------- | -------------------------------------------------- | | supported | boolean | Whether battery information is available | | loading | boolean | Whether the initial battery request is in progress | | level | number \| null | Charge level from 0 to 1 | | charging | boolean \| null | Whether the device is charging | | chargingTime | number \| null | Seconds until full | | dischargingTime | number \| null | Seconds until empty |

Time values may be Infinity when the browser cannot provide an estimate. The Battery Status API is not available in every browser. When it is unavailable or the request fails, supported and loading are false and the battery values are null.

The hook is safe to render on the server. It begins with a loading snapshot and checks browser support after the component subscribes on the client. Multiple components share one battery connection, which is removed after the last subscriber unmounts.

useMediaQuery

import { useMediaQuery } from '@hp-hooks/react'

export function ResponsiveComponent() {
  const isDesktop = useMediaQuery('(min-width: 1024px)')

  return <div>{isDesktop ? 'Desktop layout' : 'Mobile layout'}</div>
}

Server-side rendering

The hook accepts an optional fallback result:

const isDesktop = useMediaQuery('(min-width: 1024px)', false)

The fallback is used during server rendering and hydration until the client snapshot is available.

Development

This repository is a Vite+ monorepo containing the React Hooks library and a playground application.

vp install
vp -C packages/react test
vp -C packages/react pack
vp -C apps/playground dev

License

MIT.