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

usereacthelpers

v2.1.1

Published

A collection of custom React hooks

Readme

React Custom Hooks

Introduction

This package provides a collection of useful React custom hooks that help manage various aspects of a React application efficiently. These hooks include online status detection, battery status monitoring, password strength checking, input validation, idle state detection, and storage management with localStorage and sessionStorage.

Installation

To install the package, run:

npm install your-package-name

or with Yarn:

yarn add your-package-name

Available Hooks

1. useOnlineStatus

Detects whether the user is online or offline.

Usage

import { useOnlineStatus } from "your-package-name";

function App() {
  const isOnline = useOnlineStatus();
  return <div>{isOnline ? "Online" : "Offline"}</div>;
}

2. useToggle

A simple toggle hook.

Usage

import { useToggle } from "your-package-name";

const ToggleComponent = () => {
  const [isOn, toggle] = useToggle();

  return (
    <div>
      <p>{isOn ? "ON" : "OFF"}</p>
      <button onClick={toggle}>Toggle</button>
    </div>
  );
};

3. usePasswordStrength

Checks password strength based on length and complexity.

Usage

import { usePasswordStrength } from "your-package-name";

function PasswordInput() {
  const [password, setPassword] = useState("");
  const strength = usePasswordStrength(password);

  return (
    <div>
      <input
        type="password"
        value={password}
        onChange={(e) => setPassword(e.target.value)}
      />
      <p>Password Strength: {strength}</p>
    </div>
  );
}

4. useInputValidation

Validates input based on custom validation rules.

Usage

import { useInputValidation } from "your-package-name";

function EmailInput() {
  const [email, setEmail, isValid] = useInputValidation("", (value) =>
    /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value)
  );

  return (
    <div>
      <input
        type="email"
        value={email}
        onChange={(e) => setEmail(e.target.value)}
      />
      {!isValid && <p>Invalid email format</p>}
    </div>
  );
}

5. useIdle

Detects when the user has been idle for a specified time.

Usage

import { useIdle } from "your-package-name";

function IdleComponent() {
  const isIdle = useIdle(5000); // 5 seconds
  return <div>{isIdle ? "User is idle" : "Active"}</div>;
}

6. useLocalStorage

Stores and retrieves values from localStorage.

Usage

import { useLocalStorage } from "your-package-name";

function App() {
  const [name, setName] = useLocalStorage("name", "Guest");

  return (
    <div>
      <input
        type="text"
        value={name}
        onChange={(e) => setName(e.target.value)}
      />
      <p>Stored Name: {name}</p>
    </div>
  );
}

7. useSessionStorage

Stores and retrieves values from sessionStorage.

Usage

import { useSessionStorage } from "your-package-name";

function App() {
  const [theme, setTheme] = useSessionStorage("theme", "light");

  return (
    <div>
      <button onClick={() => setTheme(theme === "light" ? "dark" : "light")}>Toggle Theme</button>
      <p>Current Theme: {theme}</p>
    </div>
  );
}

Contributing

Feel free to open issues and pull requests if you have suggestions or improvements.

License

This package is licensed under the MIT License.