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

@lynkit/hooks

v0.2.2

Published

React Hooks Library

Readme

@lynkit/hooks

一个实用的 React Hooks 工具库,提供了一系列常用的自定义 Hooks,帮助你更高效地开发 React 应用。

📦 安装

npm install @lynkit/hooks

🎯 特性

  • 📦 开箱即用
  • 🎨 支持 TypeScript
  • 🔥 支持按需加载
  • 📚 详细的文档和示例
  • ⚡️ 轻量级

📚 Hooks 列表

useSetState

一个模拟类组件 setState 行为的 Hook,让函数组件也能像类组件一样方便地管理状态。

基础用法

import { useSetState } from '@lynkit/hooks';

function Demo() {
  const [state, setState] = useSetState({
    hello: 'world',
    count: 0,
  });

  return (
    <div>
      <p>hello: {state.hello}</p>
      <p>count: {state.count}</p>
      <button onClick={() => setState({ count: state.count + 1 })}>
        count + 1
      </button>
    </div>
  );
}

API

const [state, setState] = useSetState<T extends object>(initialState: T);
参数

| 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | initialState | 初始状态值 | T | - |

返回值

| 参数 | 说明 | 类型 | | --- | --- | --- | | state | 当前状态 | T | | setState | 更新状态的函数 | (state: Partial<T> \| ((prevState: T) => Partial<T>), callback?: () => void) => void |

进阶用法

  1. 对象方式更新:
setState({ hello: 'lynkit' });
  1. 函数方式更新:
setState((prev) => ({ count: prev.count + 1 }));
  1. 带回调的更新:
setState(
  { count: 100 },
  () => { console.log('状态已更新') }
);

最佳实践

  1. 表单状态管理:
const [form, setForm] = useSetState({
  username: '',
  password: '',
  remember: false,
});

// 更新单个字段
setForm({ username: 'lynn' });

// 批量更新
setForm({
  username: 'lynn',
  remember: true,
});
  1. 异步操作状态管理:
const [requestState, setRequestState] = useSetState({
  loading: false,
  data: null,
  error: null,
});

const fetchData = async () => {
  setRequestState({ loading: true });
  try {
    const data = await api.getData();
    setRequestState({ loading: false, data });
  } catch (error) {
    setRequestState({ loading: false, error });
  }
};

注意事项

  1. 初始值必须是一个对象
  2. 更新时会自动合并对象,不会覆盖未提及的字段
  3. 回调函数会在状态实际更新后执行
  4. 不要在回调函数中直接使用更新前的 state 值

🤝 贡献指南

欢迎提交 issue 和 Pull Request 帮助我们改进代码。

📄 许可证

ISC