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

@ryo-98/react-api-bridge

v1.0.4

Published

A registry for component imperative api

Readme

react-api-bridge

语言版本: English | 简体中文

React 的作用域命令式 API 桥。

React 对数据流已经有成熟方案,但对功能流还没有对应方案。
这个库提供了一种带作用域、类型安全的方式, 可以让你在 React 子树中跨组件暴露和调用方法,而不需要层层传递 props (Props Drilling)或者层层转发从forwardRef获取的Ref

| 场景 | React 的答案 | | ------- | --------------------------- | | 数据下传,单层 | props | | 数据下传,跨层 | Context | | 功能上传,单层 | useImperativeHandle | | 功能上传,跨层 | 空白(react-api-bridge来填补) |

文档

安装

npm install @ryo-98/react-api-bridge

包体积分析

npm run build:analyze

执行后会在 dist/analyze/report.html 生成静态分析报告,并在 dist/analyze/stats.json 输出原始统计数据。

它的能力

  • Boundary 做 API 作用域隔离
  • 直接调用强类型组件方法,而不是广播事件
  • 支持获取当前或父级作用域 API
  • 支持异步等待稍后挂载的 API
  • 支持同名 API 的多实例注册

快速示例

import { useState } from "react";
import {
  createBridge,
  createBoundary,
  useAPI,
  useRegister,
} from "@ryo-98/react-api-bridge";

interface AppAPIs {
  modal: {
    open: (content: string) => void;
    close: () => void;
  };
}

const bridge = createBridge<AppAPIs>();
const Boundary = createBoundary(bridge);

function ModalHost() {
  const [content, setContent] = useState<string | null>(null);

  useRegister(
    bridge,
    "modal",
    () => ({
      open: (nextContent) => setContent(nextContent),
      close: () => setContent(null),
    }),
    [],
  );

  if (!content) return null;
  return <dialog open>{content}</dialog>;
}

function OpenButton() {
  const modalAPI = useAPI(bridge, "modal");

  return (
    <button onClick={() => modalAPI.current?.open("Hello from anywhere")}>
      打开弹窗
    </button>
  );
}

export default function App() {
  return (
    <Boundary>
      <ModalHost />
      <OpenButton />
    </Boundary>
  );
}

API 一览

  • createBridge()
  • createBoundary()
  • useRegister()
  • useAPI()
  • useUpperAPI()
  • getBridgeAPI()
  • getBridgeAPIAsync()

典型场景

  • Modal、Drawer、Toast 控制器
  • Wizard、Tree 等复杂组件联动
  • 局部插件系统 API
  • 不适合抽成全局状态的命令式动作

许可证

MIT