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

captain-react-hooks

v1.0.0

Published

Collection of reusable React hooks

Readme

captain-react-hooks

A collection of reusable React hooks for common use cases.

Installation

npm install captain-react-hooks
# or
yarn add captain-react-hooks

Available Hooks

useAutosizeTextArea

A hook that automatically adjusts the height of a textarea based on its content.

import { useAutosizeTextArea } from "captain-react-hooks";

const MyComponent = () => {
  const [value, setValue] = useState("");
  const textAreaRef = useRef<HTMLTextAreaElement>(null);

  useAutosizeTextArea(textAreaRef.current, value);

  return (
    <textarea
      ref={textAreaRef}
      value={value}
      onChange={(e) => setValue(e.target.value)}
    />
  );
};

useClickOutside

A hook that triggers a callback when clicking outside of a specified element. Useful for closing modals, dropdowns, etc.

import { useOutsideClick } from "captain-react-hooks";

const MyComponent = () => {
  const [isOpen, setIsOpen] = useState(false);
  const ref = useRef(null);

  useOutsideClick(() => setIsOpen(false), ref);

  return (
    <div ref={ref}>
      {isOpen && <div>This will close when clicking outside</div>}
    </div>
  );
};

useCopyToClipboard

A hook that provides a function to copy text to the clipboard with error handling.

import { useCopyToClipboard } from "captain-react-hooks";

const MyComponent = () => {
  const { copy, error } = useCopyToClipboard();

  const handleCopy = async () => {
    const success = await copy("Text to copy");
    if (success) {
      alert("Copied!");
    } else {
      alert(`Failed to copy: ${error?.message}`);
    }
  };

  return <button onClick={handleCopy}>Copy to Clipboard</button>;
};

useEscapeKey

A hook that triggers a callback when the escape key is pressed. Useful for closing modals or canceling actions.

import { useEscapeKey } from "captain-react-hooks";

const MyComponent = () => {
  const [isOpen, setIsOpen] = useState(false);

  useEscapeKey(() => setIsOpen(false));

  return (
    <div>
      {isOpen && <div>Press ESC to close</div>}
      <button onClick={() => setIsOpen(true)}>Open</button>
    </div>
  );
};

useInterval

A hook for setting up declarative intervals. Useful for creating polling mechanisms or periodic updates.

import { useInterval } from "captain-react-hooks";

const MyComponent = () => {
  const [count, setCount] = useState(0);

  useInterval(() => {
    setCount(count + 1);
  }, 1000); // Updates every second

  return <div>Count: {count}</div>;
};

useKeyPress

A hook that detects when a specific key is pressed. Perfect for keyboard shortcuts or accessibility features.

import { useKeyPress } from "captain-react-hooks";

const MyComponent = () => {
  const isSpacePressed = useKeyPress(" ");

  return <div>{isSpacePressed ? "Space is pressed!" : "Press space..."}</div>;
};

useLocalStorage

A hook that syncs state with localStorage, providing persistent state across page reloads.

import { useLocalStorage } from "captain-react-hooks";

const MyComponent = () => {
  const [name, setName] = useLocalStorage("user-name", "");

  return (
    <input
      type="text"
      value={name}
      onChange={(e) => setName(e.target.value)}
      placeholder="Your name will be remembered"
    />
  );
};

useLockBodyScroll

A hook that prevents body scrolling. Useful for modals, drawers, or full-screen menus.

import { useLockBodyScroll } from "captain-react-hooks";

const Modal = ({ isOpen }) => {
  useLockBodyScroll(isOpen);

  return isOpen ? (
    <div className="modal">Modal content (body scroll is locked)</div>
  ) : null;
};

useOnScreen

A hook that detects when an element enters the viewport. Perfect for implementing infinite scroll or lazy loading.

import { useOnScreen } from "captain-react-hooks";

const MyComponent = () => {
  const elementRef = useRef(null);
  const isVisible = useOnScreen(elementRef, "-100px"); // 100px threshold

  return (
    <div ref={elementRef}>
      {isVisible ? "Element is visible!" : "Scroll to see me!"}
    </div>
  );
};

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT