简体   繁体   中英

Can I use react-redux to implement third party npm package for apps which are not using react-redux?

I have a react app that uses redux for the implementation. Before using redux I was able to successfully publish it as an npm package library and use it as a third party component in another react app. Then I used redux for the implementation and publish again it by simply run "npm publish" after changing the version. I was able to successfully publish it. But when I use it as a third party component in another react app which is not using redux, it gives me an error.

Is there any way to publish a package that uses react-redux, for use as a third party component in a react app which is not using redux?

Error: could not find react-redux context value; please ensure the component is wrapped in a <Provider>
▶ 21 stack frames were collapsed.
Module.<anonymous>
D:/test/my-app/src/index.js:7
   4 | import App from './App';
   5 | import reportWebVitals from './reportWebVitals';
   6 | 
>  7 | ReactDOM.render(
   8 |   <React.StrictMode>
   9 |     <App />
  10 |   </React.StrictMode>,

You could use custom context to prevent your package's redux store from clashing with a potentially already existing redux store. In that case, you would export your own Provider component that created & passed down a redux store and the consumer of your package would need to wrap that Provider around their application.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM