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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@hy_ong/react-hooks

v0.0.8

Published

React Hooks

Readme

@hy_ong/react-hooks

A collection of reusable React hooks for dialog management in modern React applications.

Installation

npm install @hy_ong/react-hooks

Hooks

useDialog

A generic hook for managing modal dialogs with custom props and response handling.

import { useDialog } from '@hy_ong/react-hooks';

// Basic usage
const dialog = useDialog<{ title: string }, string>();

// Open a dialog
dialog.open(
  { title: "Enter your name" },
  (response) => console.log("Response:", response),
  () => console.log("Cancelled")
);

// Close with response
dialog.close("John Doe");

// Cancel without response
dialog.cancel();

API:

  • show: boolean - Whether the dialog is visible
  • props: DialogProps - Current dialog props
  • response: DialogResponse | undefined - Last response from dialog
  • open(props, onClose?, onCancel?) - Open the dialog
  • close(response?) - Close dialog with optional response
  • cancel() - Cancel dialog without response

useAlert

A specialized hook for simple alert dialogs with title and description.

import { useAlert } from '@hy_ong/react-hooks';

const alert = useAlert();

// Open an alert
alert.open({
  title: "Success",
  description: "Operation completed successfully",
  onClose: () => console.log("Alert closed")
});

// Close the alert
alert.close();

API:

  • show: boolean - Whether the alert is visible
  • props: AlertProps - Current alert props
  • open(props) - Open the alert
  • close() - Close the alert

AlertProps:

  • title: string - Alert title
  • description: string - Alert description
  • onClose?: () => void - Optional close callback

useConfirm

A specialized hook for confirmation dialogs with grant/deny actions.

import { useConfirm } from '@hy_ong/react-hooks';

const confirm = useConfirm();

// Open a confirmation dialog
confirm.open({
  title: "Delete Item",
  description: "Are you sure you want to delete this item?",
  grantText: "Delete",
  denyText: "Cancel",
  onGrant: () => console.log("Confirmed"),
  onDeny: () => console.log("Denied")
});

// Grant the confirmation
confirm.grant();

// Deny the confirmation
confirm.deny();

API:

  • show: boolean - Whether the confirmation is visible
  • props: AlertProps - Current confirmation props
  • open(props) - Open the confirmation
  • grant() - Grant/confirm the action
  • deny() - Deny/cancel the action

AlertProps:

  • title: string - Confirmation title
  • description: string - Confirmation description
  • grantText?: string - Text for grant/confirm button
  • denyText?: string - Text for deny/cancel button
  • onGrant?: () => void - Optional grant callback
  • onDeny?: () => void - Optional deny callback

Example Implementation

Here's how you might implement a dialog component using these hooks:

import React from 'react';
import { useAlert, useConfirm, useDialog } from '@hy_ong/react-hooks';

function MyComponent() {
  const alert = useAlert();
  const confirm = useConfirm();
  const dialog = useDialog<{ message: string }, boolean>();

  return (
    <div>
      <button onClick={() => alert.open({
        title: "Info",
        description: "This is an information message"
      })}>
        Show Alert
      </button>

      <button onClick={() => confirm.open({
        title: "Confirm Action",
        description: "Do you want to proceed?",
        onGrant: () => console.log("User confirmed"),
        onDeny: () => console.log("User denied")
      })}>
        Show Confirmation
      </button>

      <button onClick={() => dialog.open(
        { message: "Custom dialog content" },
        (response) => console.log("Dialog response:", response)
      )}>
        Show Custom Dialog
      </button>

      {/* Render your dialog components based on the hook states */}
      {alert.show && (
        <AlertDialog
          title={alert.props.title}
          description={alert.props.description}
          onClose={alert.close}
        />
      )}

      {confirm.show && (
        <ConfirmDialog
          title={confirm.props.title}
          description={confirm.props.description}
          grantText={confirm.props.grantText}
          denyText={confirm.props.denyText}
          onGrant={confirm.grant}
          onDeny={confirm.deny}
        />
      )}

      {dialog.show && (
        <CustomDialog
          message={dialog.props.message}
          onClose={dialog.close}
          onCancel={dialog.cancel}
        />
      )}
    </div>
  );
}

Features

  • TypeScript Support: Full TypeScript support with generic types
  • Lightweight: Minimal dependencies (only React)
  • Flexible: Generic useDialog for custom implementations
  • Specialized: Pre-built hooks for common use cases
  • Modern: Built with React hooks and functional components

Development

# Install dependencies
npm install

# Run tests
npm test

# Build
npm run build

License

MIT © Ong Hoe Yuan

Repository

GitHub Repository

Issues

Found a bug or have a feature request? Create an issue