How to publish React.js + Redux component

Viewed 47

I've created React.js+Redux app that I want to publish as a reusable npm component. But do not know proper way. Here is my 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. my-test-app itself works fine on local. What would be correct code in App.js so it works in parent app? Thanks

1 Answers

I think you have to pass store instance as a prop to your app and all underlying dependencies.

Related