Fix Error: The Component For Route 'home' Must Be A React Component
Solution 1:
I think that if you change this line:
import { HomeScreen } from'./screens/HomeScreen';
to:
importHomeScreenfrom'./screens/HomeScreen';
(i.e. removing the braces around HomeScreen) then it will work. Because you used export default in the HomeScreen component's source file, you don't need the destructuring on the import. This is attempting to access a variable called HomeScreen on the component, which is resolving to undefined and causes the error you saw.
Alternatively, you can remove the default from export default and keep the import the same. I personally prefer removing the braces as the code looks cleaner.
There's also a missing closing brace on this line:
import { JoinScreenfrom'./screens/JoinScreen';
But I assumed that was a typo ;)
Solution 2:
I think that react is having a problem figuring out what to import Since you're exporting one thing by default You should replace
import { HomeScreen } from './screens/HomeScreen';
with
import HomeScreen from './screens/HomeScreen';
Solution 3:
Try with:
Home: {
screen: () => <HomeScreen/>,
},
Solution 4:
It also happens if you do not export your class.
exportdefaultclassHomeScreenextendsReact.Component {
render() {
return (
<Viewstyle={{flex:1, alignItems: 'center', justifyContent: 'center' }}><Text>Home Screen</Text><Buttontitle="Go to Details"onPress={() => this.props.navigation.navigate('Details')}
/>
</View>
);
}
}
Solution 5:
Add this to your js file at the bottom add this Line
exportdefaultMainActivity;
importReact, { Component } from'react';
import { createStackNavigator } from'react-navigation-stack';
classMainActivityextendsComponent{
...
}
exportdefaultMainActivity;

Post a Comment for "Fix Error: The Component For Route 'home' Must Be A React Component"