I've React monorepo project with React-Native and React-Native-Web.
In common module, i would like use View and Text component, but i need to change my import on mobile (react-native) or web (react).
I've try this :
const { View, Text } = window ? require('react-native-web') : require('react-native');
But that does not work, which makes sense.
Anyone have already this use case ?
Thank you !
After setting up your project to use react-native-web, you simply import everything from react-native and react-native-web takes care of the rest. If you have your project configured correctly
import { View, Text } from 'react-nativeis all you need, and on web react-native-web will render divs instead of View and p or whatever instead of Text. Code like it's react native.