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

@gedatou/cadenza-utils

v0.6.2

Published

React hooks and helpers shared across cadenza packages

Readme

@gedatou/cadenza-utils

@gedatou/cadenza-ui 内部使用的 React hooks,单独发包以便业务层直接复用。 文档:https://cadenza-ui-docs.vercel.app/docs/utils/use-controllable-state

安装

pnpm add @gedatou/cadenza-utils

useControllableState

一个状态,两种用法:外部传 value 就是受控,不传就自己管。组件作者写一次,调用方两种写法都能用。

import { useControllableState } from '@gedatou/cadenza-utils'

function Disclosure({ open, defaultOpen, onOpenChange, children }) {
  const [isOpen, setOpen] = useControllableState({
    value: open,
    defaultValue: defaultOpen,
    onChange: onOpenChange,
    fallback: false,
  })

  return (
    <>
      <button onClick={() => setOpen(!isOpen)}>切换</button>
      {isOpen && children}
    </>
  )
}

valueundefined 即受控:state 跟随 prop,setOpen 只触发 onChange,内部状态不动 —— 与 React 原生输入框的受控约定一致。否则 hook 自持状态,defaultValue 是初始值,onChange 照样触发。fallback 兜底「非受控且没给 defaultValue」的情形,让返回类型收窄为 T 而不是 T | undefined

setOpen 是标准的 Dispatch<SetStateAction<T>>:接受值或 (prev) => next 更新函数,且引用恒定,可以安全放进依赖数组。

完整契约与进阶用法见文档

resolveRenderChildren

统一解析「ReactNode 或 (values) => ReactNode」的双形态 children:封装层算好状态和默认组合,解析这一步交给它,各个 seam 的行为就是一致的。

import { resolveRenderChildren } from '@gedatou/cadenza-utils'

function SearchField({ children }: { children?: RenderChildren<SearchFieldState> }) {
  const state = { empty: value === '', disabled }
  const defaultChildren = <DefaultComposition />

  return (
    <div data-slot="search-field">
      {resolveRenderChildren(children, state, defaultChildren)}
    </div>
  )
}

函数 children 以 values 外加 defaultChildren 为参数调用;两种形态的 nullish 结果都回落到 defaultChildren——函数返回 null 同样如此,想渲染空就别传 defaultChildren。是纯函数而非 hook:它不持状态、也不碰 React 的任何东西,调用点就在组件自己的 render 体里,写成 hook 只会白白背上 rules-of-hooks 的约束。文档:https://cadenza-ui-docs.vercel.app/docs/utils/resolve-render-children

License

MIT