Fix Error: The component for route 'Home' must be a React component

ⅰ亾dé卋堺 提交于 2019-12-01 06:45:18

I think that if you change this line:

import { HomeScreen } from './screens/HomeScreen';

to:

import HomeScreen from './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 { JoinScreen  from './screens/JoinScreen';

But I assumed that was a typo ;)

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';
chandresh

It also happens if you do not export your class.

export default class HomeScreen extends React.Component {
  render() {
    return (
      <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
        <Text>Home Screen</Text>
        <Button
          title="Go to Details"
          onPress={() => this.props.navigation.navigate('Details')}
        />
      </View>
    );
  }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!