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

@jbpark/use-hooks

v2.2.0

Published

A collection of reusable React 19 hooks for common UI and interaction patterns

Downloads

133

Readme

use-hooks

English | 한국어

npm version npm downloads GitHub issues License: MIT

A collection of reusable React 19 hooks for common UI and interaction patterns. Built with TypeScript and Vite, optimized for both server-side rendering and client-side applications.

Features

  • 📦 12 Production-Ready Hooks - Utilities for scrolling, viewport, storage, and more
  • 🎯 Full TypeScript Support - Complete type definitions for better development experience
  • Tree-Shakeable - Import only what you need
  • 🔒 SSR-Safe - Built-in protection for window/document globals
  • 📱 iOS Optimized - Special handling for mobile viewport characteristics
  • 🧹 Proper Cleanup - All listeners and observers are properly cleaned up

Installation

npm install @jbpark/use-hooks

Or with pnpm:

pnpm add @jbpark/use-hooks

Usage

import {
  useLocalStorage,
  useResponsiveSize,
  useThrottle,
  useWindowScroll,
} from '@jbpark/use-hooks';

function MyComponent() {
  // Persistent state using localStorage
  const [count, setCount] = useLocalStorage('count', 0);

  // Track window scroll position
  const { y, percent } = useWindowScroll();

  // Monitor element size with breakpoints
  const { size, breakpoint, ref } = useResponsiveSize();

  // Throttled width update
  const throttledWidth = useThrottle(size.width, 200);

  return (
    <div ref={ref}>
      <p>Count: {count}</p>
      <p>Scroll: {percent.y}%</p>
      <p>Breakpoint: {breakpoint.current}</p>
      <p>Throttled width: {throttledWidth}</p>
      <button onClick={() => setCount(count + 1)}>Increment</button>
    </div>
  );
}

Available Hooks

| Hook | Description | | --------------------- | --------------------------------------------------------------------------- | | useLocalStorage | JSON-based persistent state with error handling (SSR-safe) | | useWindowScroll | Track window scroll position and percentage (iOS visualViewport compatible) | | useElementScroll | Monitor scroll state of specific elements using ResizeObserver | | useElementPosition | Monitor element bounding rect on scroll/resize (element ref support) | | useResponsiveSize | Track element size with Tailwind-like breakpoints (debounced) | | useBodyScrollLock | Lock/unlock body scroll with style preservation (iOS-specific handling) | | useScrollToElements | Scroll to specific elements by index (adjustable offset) | | useImage | Preload images and expose loading/error states | | useRecursiveTimeout | Recursively schedule async/sync callbacks | | useViewport | visualViewport support with in-app mode option and debounce | | useDebounce | Delay function execution to prevent excessive updates (autoInvoke support) | | useThrottle | Throttle value updates to a fixed interval |

Development

# Start development server with HMR
pnpm dev

# Build library (tsc + vite)
pnpm build

# Preview built library
pnpm preview

# Run lint and type check
pnpm lint

# Format code with prettier
pnpm exec prettier --write .

Project Structure

src/
├── hooks/                      # Individual hook implementations
│   ├── useBodyScrollLock/
│   ├── useDebounce/
│   ├── useElementPosition/
│   ├── useElementScroll/
│   ├── useImage/
│   ├── useLocalStorage/
│   ├── useRecursiveTimeout/
│   ├── useResponsiveSize/
│   ├── useScrollToElements/
│   ├── useThrottle/
│   ├── useViewport/
│   ├── useWindowScroll/
│   └── index.ts                # Barrel export
└── index.ts                    # Package entry point

dist/                            # Built library (ESM + types)
.changeset/                      # Changesets for versioning

Build & Deployment

This project uses Changesets for version management:

# Record changes
pnpm changeset add

# Update versions and generate CHANGELOG
pnpm changeset version

# Publish to npm
pnpm changeset publish

# Push tags
git push --follow-tags

The library is built as:

  • ES Module: dist/index.mjs
  • Type Definitions: dist/index.d.ts

Key Patterns

  • Window Protection: Hooks accessing window/document check typeof window for SSR safety (e.g., useLocalStorage)
  • Event Listeners: All scroll/resize listeners use passive flag when possible
  • ResizeObserver: Used in useResponsiveSize and useElementPosition for performance
  • requestAnimationFrame: Prevents layout thrashing in scroll/resize callbacks
  • iOS Compatibility: Special handling of iOS visualViewport in useBodyScrollLock, useWindowScroll, and useViewport
  • Debounce: Optional debouncing for resize events in useResponsiveSize and useViewport

Browser Support

  • Modern browsers (Chrome, Firefox, Safari, Edge)
  • iOS 12+ (with special visualViewport handling)
  • SSR-ready (with proper guards)

Contributing

Bug reports, feature suggestions, and code contributions are welcome!

  • 🐛 Bug Reports: Report bugs in Issues
  • 💡 Feature Requests: Suggest new features in Issues
  • 🔧 Code Contributions: Send Pull Requests for review

Please check existing issues before creating a new one to avoid duplicates.

License

MIT