'Sharing components made with Native-Base between ReactJs and React Native Projects
I am trying to share components between a ReactJs and React Native project. I have been successful in being able to share components that use React Native, but project that use Native Base get errors. My setup is this:
I have a mono repo that holds the project. I installed React Native Web in my web project I made a shared folder in in my React Native code base. I made a symlink from my web src folder to the shared folder I updated babel configs to compile items in the shared folder
Here is an example of a component I am trying to share. Nothing too special ;)
import {Center, Text} from 'native-base';
const Test = () => {
return (
<Center>
<Text>hello world!</Text>
</Center>
);
};
export default Test;
I see this in devtools console:
Uncaught Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
- You might have mismatching versions of React and the renderer (such as React DOM)
- You might be breaking the Rules of Hooks
- You might have more than one copy of React in the same app
The above error occurred in the <ForwardRef(Center)> component:
Any idea how I can get components with native base to work in web. I should note that it works fine on mobile, where there is not a symlink.
Solution 1:[1]
The only way to share components between web and native mobile is with expo, or with react-native-web. I use react-native-web, and I am happy with the technology. Write once play everywhere (web, android & ios)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Ioannis Apostolou |