[英]How to publish React.js + Redux component
I've created React.js+Redux app that I want to publish as a reusable npm component.我创建了 React.js+Redux 应用程序,我想将它作为可重用的 npm 组件发布。 But do not know proper way.但不知道正确的方法。 Here is my App.js这是我的 App.js
import React from 'react';
import MyComponent from './MyComponent';
import { Provider } from 'react-redux';
import store from './MyComponent/store';
import { ThemeProvider } from 'styled-components';
function App() {
return (
<Provider store={store}>
<ThemeProvider theme={xxxxxxx}>
<MyComponent/>
</ThemeProvider>
</Provider>
);
}
export default App;
I published it then trying to call it from other app.我发布了它,然后尝试从其他应用程序调用它。
>> npm install my-test-app@0.0.1
import MyComponent from 'my-test-app';
...
<MyComponent />
The app starts but seems MyComponent has no access to store and theme provider.该应用程序启动,但似乎 MyComponent 无权访问商店和主题提供程序。 my-test-app itself works fine on local. my-test-app 本身在本地运行良好。 What would be correct code in App.js so it works in parent app? App.js 中的正确代码是什么,以便它在父应用程序中工作? Thanks谢谢
I think you have to pass store instance as a prop to your app and all underlying dependencies.我认为您必须将商店实例作为道具传递给您的应用程序和所有底层依赖项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.