Search code examples
javascriptreactjsweb-componentpackage.jsonrollup

How to use web component converted from react component using react-to-webcomponent library in other projects react/vue/svelte/etc


My web component is working fine If I add the react and react-dom as peer dependencies in other react projects but because I want this component to also work in other frameworks like Vue/svelte/vanilla etc., therefore, I added react and react-dom to dependencies but then I am getting cannot read property use ref of undefined react_min_production kind of error in the browser and it crashes.

So how can I achieve this? Or do I have to use the react component itself for the react project and the web component for the rest of the projects?

Thank you!


Solution

  • I got it working by adding the react and react-dom as dependency so it will include it in the bundle no matter which version other projects are using. Thank you!