
Company News
Socket Partners with Replit to Block Malicious Packages in AI-Powered Development
Replit is integrating Socket Firewall into its AI-powered development experience to help protect builders from malicious open source packages.
@empjs/bridge-react
Advanced tools
EMP Bridge React 是一个用于跨 React 版本组件通信的桥接工具,它解决了不同 React 版本之间组件共享和通信的问题。
# 使用 npm
npm install @empjs/bridge-react
# 使用 yarn
yarn add @empjs/bridge-react
# 使用 pnpm
pnpm add @empjs/bridge-react
// 在 React 16/17 应用中
import React from 'react';
import { createBridgeComponent } from '@empjs/bridge-react';
// 创建要共享的组件
const MyComponent = (props) => {
return <div>Hello from React 16/17! {props.message}</div>;
};
// 导出桥接组件
export default createBridgeComponent(MyComponent, {
React,
ReactDOM: require('react-dom'),
// React 18+ 才有 createRoot
// createRoot: require('react-dom/client').createRoot
});
// 在 React 18/19 应用中
import React from 'react';
import { createRemoteAppComponent } from '@empjs/bridge-react';
// 导入远程组件(可以是动态导入)
import RemoteComponent from 'remote-app/MyComponent';
// 创建可在当前 React 版本中使用的组件
const BridgedComponent = createRemoteAppComponent(
RemoteComponent,
{
React,
ReactDOM: require('react-dom'),
createRoot: require('react-dom/client').createRoot
},
{
onError: (error) => console.error('Failed to load component:', error)
}
);
// 在应用中使用
function App() {
return (
<div>
<h1>My App (React 18/19)</h1>
<BridgedComponent message="Passed from React 18/19" />
</div>
);
}
用于生产者包装应用级别导出模块。
function createBridgeComponent(
Component: React.ComponentType<any>,
options: {
React: any;
ReactDOM: any;
createRoot?: Function;
}
): BridgeProvider
参数:
Component: 要导出的 React 组件options: React 相关配置
React: React 实例ReactDOM: ReactDOM 实例createRoot: (可选) React 18+ 的 createRoot 方法用于消费者加载应用级别模块。
function createRemoteAppComponent(
component: ComponentProvider,
reactOptions: {
React: any;
ReactDOM: any;
createRoot?: Function;
},
options?: {
onError?: (error: Error) => void;
}
): React.ComponentType<any>
参数:
component: 组件提供者函数,可以是同步或异步的reactOptions: 当前应用的 React 相关配置
React: React 实例ReactDOM: ReactDOM 实例createRoot: (可选) React 18+ 的 createRoot 方法options: (可选) 额外配置
onError: 错误处理回调函数FAQs
Emp Bridge React
The npm package @empjs/bridge-react receives a total of 5 weekly downloads. As such, @empjs/bridge-react popularity was classified as not popular.
We found that @empjs/bridge-react demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Replit is integrating Socket Firewall into its AI-powered development experience to help protect builders from malicious open source packages.

Security News
npm confirmed a tooling bug incorrectly marked several one-character packages as security holders and said it was working on a rollback.

Research
/Security News
Newer packages in this compromise use native extensions and .pth loaders to execute JavaScript stealers in developer environments.