3
votes

Is that possible to create an hybrid package for React and React-Native that requires specific import, for instance using React-Native I'll have to import AsyncStorage but I'll not need this one for React (using localStorage).

So I was wondering if that's feasible to handle both case using conditional detecting if the app is React-Native or not.

2

2 Answers

0
votes

In order to detect if the app is React-Native or not, you will need to use platform specific logic. According to this commit, you should be able to check via:

navigator.product === 'ReactNative'

Also see here for specific platforms: https://facebook.github.io/react-native/docs/platform-specific-code.html

0
votes

For those who can be interested in the future by the implementation of a library that needs specific imports for React and specific imports for React-Native, but can't be mixed, you'll need to create a store for your library, if it can be initialized with React code, you can initialize in your code and create a setter function that'll create a new store to inject the specific dependencies.