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

simform-custom-hook

v0.1.6

Published

A collection of Custom Hooks for React.

Readme

Documentation

📗 Index

💾 useLocalStorage

Custom useState hook which saves the state value in localStorage

Usage

import React from "react";
import { useLocalStorage } from "simform-custom-hook";
const LocalValue = () => {
  const [name, setName] = useLocalStorage("ram", "name");
  /*
   If name exists in localStorage, the value of name state will be
   localStorage.getItem("name"). If name doesn't exist in localStorage, 
   the value of the state will be "ram" and a new item will be created in
   localStorage will key "name"
  */
  return <span>Value from localstorage is {name}</span>;
};

Parameters

  1. initialValue (any) : Initial value of the state.
  2. key (String) : Key for the localStorage.

Return value

[state,setState]

  1. state (any) : The created state.
  2. setState (function) : Function to change the state value.

🏀 useDebounce

Convert a normal function to a debounced function.

Note: More about Debouncing : here

Usage

import React, { useState } from "react";
import { useDebounce } from "simform-custom-hook";
const LocalValue = () => {
  const [value, setValue] = useState("");
  const debouncedValue = useDebounce(value, 500);

  const handleChange = (event) => {
    setValue(event.target.value);
  };

  return (
    <div>
      <p>Value real-time: {value}</p>
      <p>Debounced value: {debouncedValue}</p>
      <input type="text" value={value} onChange={handleChange} />
    </div>
  );
  /*
   No matter how many times we call this function in 500ms, it will only
   execute once.
  */
};

Parameters

[inputFunction,delay]

  1. inputFunction (function) : Function which is to be modified.
  2. delay (number) : The time delay in milliseconds.

Return value

debouncedFunction (function) : The modified function.

🔘 useToggle

Returns a boolean state and a state toggle function.

Usage

import React from "react";
import { useToggle } from "simform-custom-hook";
const Mood = () => {
  const [isHappy, toggleIsHappy] = useToggle(true);
  /*
    If isHappy state is true calling toggleIsHappy function will set
    the isHappy state to false, and vise versa.
  */
  return (
    <div>
      <h1>Hello World</div>
      <p>{`The user is ${isHappy ? "Happy 😃" : "Sad 😢"}`}</p>
      <button onClick={toggleIsHappy}>Toggle</button>
    </div>
  );
};

Parameters

  1. initialValue (boolean) : Initial value of the state.

Return value

[state,toggleFunction]

  1. state (boolean) : The booelan state.
  2. toggleFunction (function) : Function to toggle the state value.

🖱 useMousePosition

Returns an object with the current coordinates of the mouse pointer.

Usage

import React from "react";
import { useMousePointer } from "simform-custom-hook";
const Mouse = () => {
  const { x, y } = useMousePosition();
  /*
    Using Object destructuring to get x & y coordinates
    from mousePosition object.
  */
  return (
    <div>
      <h1>Mouse Pointer Location</div>
      <p>The mouse pointer is at : {`(${x},${y})`}</p>
      {/* The x,y coordinates will be updated as you move your mouse.*/}
    </div>
  );
};

Parameters

None : This hooks takes no parameters.

Return value

{x,y}

  1. x (number) : X Coordinate of the mouse.
  2. y (number) : Y Coordinate of the mouse.

🕒 usePrevious

Custom hook for retrieving the previous useState value

Usage

import React from "react";
import { usePrevious } from "simform-custom-hook";
function App() {
  // normal usage of useState
  const [visible, setVisible] = useState(false);

  // using the custom usePrevious hook to retrieve the value that was provided in the previous render
  const prevVisibility = usePrevious(visible);

  // Display both current and previous visibility states
  return (
    <div>
      <h1>Current visibility: {visible ? "visible" : "not visible"}</h1>
      <h1>Previous visibility: {prevVisibility ? "visible" : "not visible"}</h1>
      <button onClick={() => setVisible(!visible)}>Toggle Visibility</button>
    </div>
  );
}

Parameters

presentState (any) : The current value (will be the previous value in the next render).

Return value

previousState (any) : The previous state.

📱 useMediaQuery

Custom hook which listens for a media query and updates the state when the query is active/inactive

Usage

import React from "react";
import { useMediaQuery } from "simform-custom-hook";
const BottomNav = () => {
  const isMobileDevice = useMediaQuery("(max-width:600px)");
  /*
   isMobileDevice will be true when the screen size is less than
   600px, and false otherwise
  */
  // Component will only be rendered in mobile devices
  return isMobileDevice ? <div className="bottom-nav"></div> : null;
};

Parameters

  1. mediaQuery (String) : The media query to listen to.

Return value

  1. isMediaQueryActive (any) : A boolean state denoting if the media query is active or not

📱 useCopyToClipboard

Custom hook which copy the data and can be used whenever needed.

Usage

import React from "react";
import { useCopyToClipboard } from "simform-custom-hook";

const App = () => {
const [values, copy] = useCopyToClipboard();
  /*
   isMobileDevice will be true when the screen size is less than
   600px, and false otherwise
  */
  // Component will only be rendered in mobile devices
  return (
    <>
      <h1>Click to copy:</h1>
      <div style={{ display: "flex" }}>
        <button onClick={() => copy("A")}>A</button>
        <button onClick={() => copy("B")}>B</button>
        <button onClick={() => copy("C")}>C</button>
      </div>
      <p>Copied value: {values ?? "Nothing is copied yet!"}</p>;
    </>
  );
};