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

@skyroc/hooks

v0.2.0

Published

React hooks - platform-agnostic core with ./web subpath for browser hooks

Readme

@skyroc/hooks

与业务无关的通用 React Hooks 集合。通过 subpath exports 区分平台无关 hooks 和浏览器特定 hooks。

架构

@skyroc/hooks
├── "."      → 平台无关 hooks(React Native 安全)
└── "./web"  → 浏览器 hooks + re-export 全部平台无关 hooks

分层设计

包内部按平台特性分为两层:

  • 主出口(.:只包含不依赖 DOM / 浏览器 API 的 hooks。可以安全用于 React Native 等非浏览器环境。允许依赖 ahooks 中平台无关的部分(如 useBooleanuseCountDown)。
  • Web 出口(./web:包含依赖 windowdocumentnavigator 等浏览器 API 的 hooks。自动 re-export 主出口全部内容,Web 端消费者只需关注这一个入口。

位置语义

本包位于 packages/hooks/packages/* 中间层),而非 packages/@core/packages/web/

  • 不放 @core:因为依赖了 ahooks 等第三方库,@core 要求零外部依赖
  • 不放 web:因为主出口的 hooks 与浏览器无关,放在 web 语义不准确

与 ahooks 的关系

  • ahooks 是本包的 dependency,作为内部实现细节使用
  • 不 re-export ahooks 的任何内容。消费者如需直接使用 ahooks(如 useSizeuseKeyPress),应在自己的包中安装 ahooks 并直接 import

使用

// Web 应用 — 从 ./web 导入,拿到全部 hooks
import { useArray, useCopy, useLoading } from '@skyroc/hooks/web';

// React Native — 从主出口导入,只有平台安全的 hooks
import { useArray, useLoading } from '@skyroc/hooks';

新增 Hook 规则

判断放在哪里

| 条件 | 放入 | |------|------| | 不依赖 DOM / 浏览器 API | src/ → 从 . 导出 | | 依赖 windowdocumentnavigatormatchMedia 等 | src/web/ → 从 ./web 导出 | | 依赖业务逻辑、i18n、特定 feature、特定 UI 库组件 | 不放本包,留在 app 层 |

判断依据

关注的是 hook 运行时是否需要浏览器环境,而非它依赖的库是否"web 向"。例如 ahooks 的 useBoolean 虽然来自一个 Web 向的库,但它本身不调用任何浏览器 API,所以封装它的 hook 放在主出口。

编码规范

遵循项目 CLAUDE.md 中定义的 React 编码规则,关键点:

  • 禁止 useCallback:内部函数使用 function 声明
  • useMemo 仅限两种场景:派生值、确实昂贵的计算
  • 所有 hook 使用 function 声明导出(非箭头函数,hooks 不是组件)
  • 内部辅助函数使用 function 声明,不用箭头函数
  • 文件必须包含显式 import,不依赖 auto-import(子包没有 auto-import 配置)

导出清单维护

新增 hook 后需要更新对应的 barrel export:

  • 平台无关 hook → 更新 src/index.ts
  • 浏览器 hook → 更新 src/web/index.ts(主出口会被 web 出口自动 re-export,不需要两边都加)