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

ohook

v1.0.1

Published

oh hook !

Readme

Build Status Coverage Status NPM Version NPM Download GitHub license

List Of Hooks

State

LifeCycle

SideEffect

DOM

Installation

yarn add ohook
# or
npm i ohook

Usage

codesandbox example

useClassicalState

setState like Class Component.

const [state, setState] = useClassicalState({ isLoading: true, data: [] })

setState({ isLoading: false, data: [1, 2] }) // setState like Class Component

useToggle

Like useState, but can only become true or false.

  • initialState - initial state or initial state setter as for useState
const [state, toggle] = useToggle() // detault: false

toggle() // toggle !state
toggle(true) // toggle true
toggle(false) // toggle false

useMount

Run effect only when component is first mounted.

useMount(() => {
  // DidMount ...
  return () => {
    // WillUnmount
  }
})

useShow

Run effect when component is visible after useMount and document visibilitychanged.

useShow(() => {
  // Run when visible

  return () => {
    // Run when not visible
  }
})

useWillUnmount

Run effect only when component is unmounted.

useWillUnmount(() => {
  // code
})

useDidUpdate

Effect hook that ignores the first render (not invoked on mount)

function useDidUpdate(effect: React.EffectCallback, deps?: React.DependencyList): void

const state = useState(1)

useDidUpdate(() => {
  // code
}, [state])

useTimeout

handle the setTimeout timer function. Can be called repeatedly.

Returns:

  • (Function): Returns the new timeout function.
useTimeout(fn: () => void, delay: number | undefined ,immediate: boolean);

const fn = useTimeout(() => {}, 1000, true) // auto run after 1s
const fn2 = useTimeout(() => {}, 1000, false) // run effect when u call it

fn() // Cancel the previous one and retime it.
fn2() // run after 1s

useInterval

handle the setTimeout timer function, base on useTimeout. Can be called repeatedly.

useInterval(fn: () => void, delay: number | undefined ,immediate: boolean);

const fn = useInterval(() => {}, 1000, true) // auto run after 1s
const fn2 = useInterval(() => {}, 1000, false) // run effect when u call it

fn() // Cancel the previous one and retime it.
fn2() // run after 1s

useDebounceFn

handle the debounce function base on lodash.debounce.

Returns:

  • (Function): Returns the new debounce function.
// Use it like loadsh.debounce
const fn = useDebounceFn(() => {
  fetch('...')
}, 1000)

<input onChange={fn} />

useThrottleFn

handle the throttle function base on lodash.throttle.

Returns:

  • (Function): Returns the new throttled function.
// Use it like loadsh.throttle
const fn = useThrottleFn(() => {
  setState(/* */)
}, 1000)

<div onScroll={fn} />

useOnOutsideClick

Triggers callback when user clicks outside the target element.

  • withKeyboard - Click the esc button to trigger.

Returns:

  • useRef().
function useOnOutsideClick<T extends HTMLElement>(
  onOutsideClick: (event: MouseEvent | KeyboardEvent) => void,
  isListening: boolean = false,
  withKeyboard?: boolean = false
): React.RefObject<T>

const ref = useOnOutSideClick(() => {}, true)


<div ref={ref} />

useEventTarget

The hook encapsulates onChange and value logic for form controls that obtains value through event.target.value. It also supports custom transformer and reset functionalities.

const [value, {  onChange, reset }] = useEventTarget({ initialValue: 'this is initial value' })


<input onChange={fn} />
<button onClick={reset}/>