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

@curiosbasant/react-compooks

v0.4.0

Published

Curios's frequently used react hooks collection.

Downloads

20

Readme

@curiosbasant/react-compooks

This is my frequently used react hooks, which I'll install in almost every project I create or work on. So that I don't have to keep copy pasting the files in each project.

Most of them are inspired by WDS on youtube

To install

yarn add @curiosbasant/react-compooks

OR

npm install @curiosbasant/react-compooks

React Hooks

These hooks can work on all react applications

useDebugInfo

function ExampleComponent() {
  const info = useDebugInfo("example-component")
  return (

  )
}

useEffectOnce

Same as react's useEffect, but only run once the component mounts. It doesn't requires any dependencies.

function ExampleComponent() {
  const [loading, toggleLoading] = useToggle(true)

  useEffectOnce(() => {
    toggleLoading()
  })

  return // JSX
}

useFunctionalReducer

const ActionMap = {
  increment(draft, by = 1, allowNegative = false) {
    if (allowNegative || by > 0) {
      draft.count += by
    }
  },
  decrement(draft, by = 1) {
    draft.count -= by
  },
}
const initialState = {
  count: 0,
}

function ExampleComponent() {
  const [state, dispatch] = useFunctionalReducer(ActionMap, initialState)
  return (
    <div>
      <button onClick={() => dispatch.decrement()}>Decrement</button>
      <button onClick={() => dispatch.increment(-5, true)}>Increment</button>
    </div>
  )
}

useRenderCount

Tracks the number of times, the component has been rerendered since last reset.

function ExampleComponent() {
  const [count, reset] = useRenderCount()
  return (
    <div>
      <span>Render Count: {count}</span>
      <button onClick={() => reset()}>Reset Count</button>
    </div>
  )
}

useToggle

Provides a bool value (default false) that can be toggled.

function ExampleComponent() {
  const [bool, toggleBool] = useToggle()
  return (
    <div>
      <span>Bool Value: {bool}</span>
      <button onClick={() => toggleBool()}>Toggle Bool</button>
    </div>
  )
}

useValidatorState

Validates a state before updating it.

function ExampleComponent() {
  const [value, setValue, isValid] = useValidatorState(5, (val) => val < 10)
  return // JSX
}

React Web Hooks

These hooks only works in browsers

useLocalStorage (and useSessionStorage)

Tries to get a value from browser's localstorage, if it doesn't exist returns the optionally provided default value, otherwise returns null. The third return value, completely removes the key from localstrorage

function ExampleComponent() {
  const [userId, setUserId, removeUserId] = useLocalStorage("userId", "default-id")
  return // JSX
}

useEventListener

Listens to browser's dom events, on the optinally provided element-ref or window otherwise.

function ExampleComponent() {
  const divRef = useRef()
  useEventListener("mouseover", () => {}, divRef)
  return <div ref={divRef}>Hover me!</div>
}

useTimeout

Uses the setTimeout function, to run the callback after a certain amount of time. Also returns two methods viz. reset (to reset the time) and clear (to cancel)

function ExampleComponent() {
  const { reset, clear } = useTimeout(() => {}, 1000)

  return // JSX
}

useOnlineStatus

Uses the useEventListener hook, to detect if user has internet connectivity.

function ExampleComponent() {
  const isOnline = useOnlineStatus()

  return // JSX
}