Creating a React and React Native component in a single npm package

107 Views Asked by At

Is it possible to create a component, living in a single npm package, that would work in both React and React Native?

I have created two variations of a component (View vs div and so on), one for the web and one for react native. I could easily use a build script or something like preprocessor.js to build a react or react-native output of the library but is there a better way?

Have anyone had any luck building a component that you could simply npm install into a react or react native project and just have it use the correct implementation? Or would I have a problem where both the react and react-native dependencies would exist in my package.json? Thanks!

0

There are 0 best solutions below