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

reactilities

v0.7.0

Published

A comprehensive collection of useful React hooks and utilities for modern web development

Readme

Reactilities

A comprehensive collection of useful React hooks and utilities for modern web development. Built with TypeScript for excellent developer experience and type safety.

npm version CI codecov TypeScript

Installation

npm install reactilities
# or
yarn add reactilities
# or
pnpm add reactilities

Requirements

  • React >= 18.0.0 (tested against React 18 and 19)
  • React DOM >= 18.0.0

Note: This library uses useSyncExternalStore, which requires React 18 or higher.

Importing

Import everything from the package root, or a single hook from its subpath — both tree-shake to only the code you use:

import { useDebounce, useLocalStorage } from 'reactilities';
// or, per-hook subpath (ships ~0.5 KB for one hook):
import { useDebounce } from 'reactilities/useDebounce';

Next.js / React Server Components

Every hook ships with the "use client" directive, so you can import them from Client Components in the Next.js App Router without any wrapper. Hooks that read browser-only state (useMediaQuery, useLocalStorage, useSessionStorage, useNetworkState, useDarkMode, useWindowSize, …) are built on useSyncExternalStore and return a stable server snapshot during SSR, so they never crash server rendering and produce no hydration mismatch — the real value applies after mount.

Features

  • 70+ React Hooks — DOM manipulation, state management, async, timers, and more
  • Lifecycle Helpers — class component lifecycle methods as hooks
  • Helper Functions — utility functions for common tasks
  • TypeScript Types — utility types for better type safety
  • TypeScript First — full type support with excellent IntelliSense; verified with publint and are-the-types-wrong (works under bundler, node16, and nodenext)
  • Well Tested — 857 tests on a React 18 + 19 CI matrix
  • Tree Shakable — package-root or per-hook subpath imports
  • Zero Dependencies — no external dependencies except React
  • SSR Safe — built for the Next.js App Router; browser-backed hooks return server snapshots instead of throwing
  • Comprehensive Docs — each hook has its own detailed README

API Reference

Each hook and utility has its own detailed documentation with examples. Click on any item below to see full documentation.

DOM Hooks

Hooks for DOM manipulation and browser APIs.

State Hooks

Hooks for state management and persistence.

  • useBoolean - Boolean state with named setTrue/setFalse/toggle controls
  • useClipboard - Read from and write to the clipboard with hasCopied tracking
  • useCookie - Read and write browser cookies
  • useCopyToClipboard - Copy text to clipboard with fallback
  • useCounter - Numeric counter with min/max bounds and step
  • useList - Manage array state with push, remove, sort, and more
  • useLocalStorage - Persist state in localStorage with sync
  • useMap - Manage Map state with React integration
  • useObjectState - Manage object state with partial updates
  • usePrevious - Access the previous render's value
  • useSessionStorage - Persist state in sessionStorage
  • useSet - Manage Set state with React integration
  • useStep - Multi-step wizard and onboarding flow state management
  • useToggle - Toggle boolean state with flexible API
  • useUndoRedo - State with full undo/redo history

Utility Hooks

Performance and utility hooks for common patterns.

Lifecycle Hooks

Class component lifecycle methods as hooks.

Helper Functions

Utility functions for common tasks.

TypeScript Types

Utility types for better type safety.

  • Nullable<T> - Makes a type nullable (T | null)
  • Maybe<T> - Makes a type nullable and undefined (T | null | undefined)
  • ValueOf<T> - Extracts all possible values from an object type
  • DeepPartial<T> - Makes all properties optional recursively
  • VoidFunction<T> - Type for void-returning functions with typed parameters

Quick Start

import {
  useLocalStorage,
  useDebounce,
  useWindowSize,
  useFetch,
  useUndoRedo,
  useInfiniteScroll,
  classnames
} from 'reactilities';

function App() {
  // Persist theme preference
  const [theme, setTheme] = useLocalStorage('theme', 'light');

  // Responsive layout
  const { width } = useWindowSize();
  const isMobile = width > 0 && width < 768;

  // Debounce search input
  const [search, setSearch] = useState('');
  const debouncedSearch = useDebounce(search, 300);

  // Fetch with loading state
  const { data, loading } = useFetch<User[]>(
    `/api/users?q=${debouncedSearch}`
  );

  const buttonClass = classnames('btn', {
    'btn-primary': theme === 'light',
    'btn-dark': theme === 'dark',
    'btn-sm': isMobile,
  });

  return (
    <div>
      <button className={buttonClass} onClick={() => setTheme(t => t === 'light' ? 'dark' : 'light')}>
        Toggle Theme
      </button>
      <input
        value={search}
        onChange={e => setSearch(e.target.value)}
        placeholder="Search..."
      />
      {loading ? <Spinner /> : <UserList users={data ?? []} />}
    </div>
  );
}

TypeScript Support

All hooks and utilities are written in TypeScript with full type definitions:

// Type inference works automatically
const [user, setUser] = useLocalStorage('user', { name: 'John', age: 30 });
// user is typed as { name: string; age: number }

// Generic types are supported
const debouncedValue = useDebounce<string>('hello', 300);
const throttledValue = useThrottle<number>(scrollY, 100);

// Async hooks are fully typed
const { data } = useFetch<User[]>('/api/users');
// data is User[] | null

// Utility types
type User = { id: string; name: string; email: string };
type NullableUser = Nullable<User>;     // User | null
type MaybeUser = Maybe<User>;           // User | null | undefined
type PartialUser = DeepPartial<User>;   // All properties optional recursively

Testing

Reactilities comes with comprehensive tests:

  • 857 tests covering all functionality
  • Run on every commit against React 18 and React 19 (CI matrix)
  • Tested with Vitest and React Testing Library

License

MIT © Petar Basic

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Changelog

See CHANGELOG.md for the full version history. Notable changes are kept there following Keep a Changelog.


Support

If you find this library useful and are feeling generous, consider donating to Svratište — a day center in Belgrade providing support, meals, and shelter for people experiencing homelessness.

Facebook Instagram Donate


Made with ❤️ by Petar Basic