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

@khanglvm/react

v1.2.0

Published

React utilities for shared state, typed translations, browser events, and component helpers.

Readme

@khanglvm/react

React utilities for shared state, translation, and browser events, with helpers for component props and children.

I built these to reuse the setup that kept appearing in my React work. createContextState is the main state utility: one factory gives you typed selector hooks, Immer draft updates, and a revert function for each update. The other tools work independently.

Choose a tool

| When you need to… | Start here | What it adds | | --- | --- | --- | | Share editable state across components | createContextState | Selectors, draft updates, and per-update rollback in one API | | Keep translation keys and language variants together | defineLocale / createTranslator | Typed dictionaries, namespace hooks, and text substitution | | Ask mounted components for an async response | createEventMethod | Typed event data and collected listener results | | Reuse equality, caching, or React child checks | Helpers | Small functions with explicit behavior and limits |

For state owned by one component, useState is usually enough. These utilities help when several components share the same work. Read the guides for examples and tradeoffs before choosing one.

Install

Use React 18 or 19. The package ships ES modules and TypeScript declarations.

npm install @khanglvm/react

The npm package includes the state utility, translations, browser events, and component helpers. Import what you need; the utilities work independently.

Shared state in one file

Put this in App.tsx in a React TypeScript app. In Next.js App Router, add 'use client' as the first line.

import { createContextState } from '@khanglvm/react'

type CounterState = { count: number }

const {
  Provider,
  useContextStateValue: useCounterValue,
  useSetContextState: useSetCounter,
} = createContextState<CounterState>()

function CounterValue() {
  const count = useCounterValue(state => state.count)
  return <p>Count: {count}</p>
}

function IncrementButton() {
  const setState = useSetCounter()

  return (
    <button onClick={() => setState(draft => { draft.count += 1 })}>
      Add one
    </button>
  )
}

export default function App() {
  return (
    <Provider initialState={{ count: 0 }}>
      <CounterValue />
      <IncrementButton />
    </Provider>
  )
}

Create the state utility outside component renders. Initialize every field your selectors read, keep selectors pure, and use the setter to change state. A hook outside its provider cannot update the store.

More examples

createStateManager remains available for older hook names. Use createContextState in new code.

Using a coding agent

Give your agent the repository URL and a small task:

Read the README and the guide for the relevant utility in https://github.com/khanglvm/react. Explain whether it fits this feature before adding it. Install @khanglvm/react from npm, preserve the documented API, and check the example against my app's React version. For shared state, use typed selectors and Immer draft updates under the matching provider.

By Khang Le. MIT licensed.