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

@buzuosheng/hooks

v1.1.0

Published

自定义react hooks, 包含useDebounce, useWorker等

Readme

@buzuosheng-hooks

一个实用的 React Hooks 库,提供了常用的自定义 Hooks,帮助你更高效地处理防抖、状态管理、Web Worker 等功能。

✨ 特性

  • 🔍 类型安全:使用 TypeScript 编写,提供完整的类型定义
  • 📦 轻量级:无外部依赖(除 immer 和 shallowequal),体积小巧
  • 🧪 测试完善:完整的单元测试覆盖
  • 📃 文档详尽:每个 Hook 都有详细的文档和使用示例
  • 🛠️ 优化性能:减少重渲染,优化计算任务

📦 安装

# 使用 npm
npm install @buzuosheng/hooks

# 使用 yarn
yarn add @buzuosheng/hooks

# 使用 pnpm
pnpm add @buzuosheng/hooks

注意:如果使用 useImmer Hook,还需要安装 immer 作为依赖。

🔨 使用示例

import { useDebounce, useImmer, useWorker } from '@buzuosheng/hooks';

// 防抖处理输入
function SearchComponent() {
  const [text, setText] = useState('');
  const debouncedText = useDebounce(text, 500);
  
  useEffect(() => {
    // 只在 debouncedText 变化时执行
    fetchSearchResults(debouncedText);
  }, [debouncedText]);
  
  return (
    <input 
      value={text}
      onChange={e => setText(e.target.value)}
      placeholder="搜索..."
    />
  );
}

// 使用 Immer 简化状态更新
function TodoApp() {
  const [todos, updateTodos] = useImmer([]);
  
  const addTodo = title => {
    updateTodos(draft => {
      draft.push({ id: Date.now(), title, completed: false });
    });
  };
  
  const toggleTodo = id => {
    updateTodos(draft => {
      const todo = draft.find(t => t.id === id);
      if (todo) todo.completed = !todo.completed;
    });
  };
  
  // ...组件其余部分
}

📚 可用 Hooks

  • useDebounce — 用于处理防抖值的 Hook,避免频繁更新。
  • useDebouncedCallback — 用于处理防抖函数的 Hook,附带取消和立即执行功能。
  • useImmer — 用于简化不可变状态更新的 Hook,基于 Immer。
  • useShallow — 用于优化状态更新的 Hook,支持浅比较和函数式更新。
  • useWorker — 用于在 Web Worker 中执行耗时计算的 Hook,避免阻塞主线程。

📃 详细文档

每个 Hook 都有详细的文档,包括类型定义、参数说明、使用示例、注意事项等。点击上面的链接查看完整文档。

🔗 相关链接

📄 许可证

MIT © buzuosheng