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

@ohkit/react-helper

v0.0.5

Published

some utils and hooks for react

Readme

@ohkit/react-helper

React辅助工具集合,提供常用React工具函数和hooks

安装

npm install @ohkit/react-helper

功能特性

  • Ref处理工具
  • 运行时状态管理hook
  • SSR兼容的effect hook
  • 类型安全

基本用法

Ref处理

import { assignRef } from '@ohkit/react-helper';

function Component({ ref1, ref2 }) {
  const internalRef = useRef();
  
  useEffect(() => {
    assignRef(ref1, internalRef.current);
    assignRef(ref2, internalRef.current);
  }, []);

  return <div ref={internalRef}>...</div>;
}

运行时状态

import { useRuntime } from '@ohkit/react-helper';

function Component(props) {
  const [runtime, assignRuntime] = useRuntime({
    count: 0,
    name: 'default'
  });

  // 更新运行时状态
  assignRuntime({ count: 1 });
}

SSR兼容effect

import { useCompatibleEffect } from '@ohkit/react-helper';

function Component() {
  useCompatibleEffect(() => {
    // 在浏览器端使用useLayoutEffect
    // 在SSR环境使用useEffect
  }, []);
}

API 说明

工具函数

| 函数 | 说明 | 参数 | 返回值 | |------|------|------|--------| | assignRef | 分配ref到多个目标 | registerRef: Ref, ref: RefValue | void |

Hooks

| Hook | 说明 | 参数 | 返回值 | |------|------|------|--------| | useRuntime | 运行时状态管理 | init: T, syncKeys?: Array<keyof T> | [T, AssignRuntime<T>] | | useCompatibleEffect | SSR兼容effect | effect: EffectCallback, deps?: DependencyList | void |

高级用法

组合使用

function SmartComponent({ ref, ...props }) {
  const [runtime, assignRuntime] = useRuntime({
    mounted: false,
    width: 0
  });

  const internalRef = useRef();

  useCompatibleEffect(() => {
    assignRuntime({ mounted: true });
    assignRef(ref, internalRef.current);
  }, []);

  return <div ref={internalRef}>...</div>;
}

注意事项

  1. useRuntime适合管理组件内部状态,不替代Redux等状态管理
  2. assignRef可以处理callback ref和object ref
  3. 在SSR项目中使用useCompatibleEffect确保兼容性