Expoを用いてアプリ開発をしてみようと思いこちらの記事を参考に始めてみたのですが、React Navigationを使用したところ以下のエラーが出てしまいました。
自分でも調べてみたのですが、解決方法がよくわからなかったのでご教示していただけないでしょうか。
error
1Error: The component for route 'Main' must be a React component. For example: 2 3import MyScreen from './MyScreen'; 4... 5Main: MyScreen, 6} 7 8You can also use a navigator: 9 10import MyNavigator from './MyNavigator'; 11... 12Main: MyNavigator, 13}
以下がソースコードです。
App.js
App
1import React, {Component} from 'react'; 2import { createStackNavigator } from 'react-navigation-stack'; 3 4import Main from './screens/Main'; 5import Push from './screens/Push'; 6import Modal from './screens/Modal'; 7 8 9 10const MainNavigation = createStackNavigator( 11 { 12 Main: { screens: Main }, 13 Push: { screens: Push }, 14 }, 15 {initialRouteName: 'Main', mode: 'card', headerMode: 'none'} 16) 17const NestNavigation = createStackNavigator( 18 { 19 MainNavigation: { screens: MainNavigation }, 20 Modal: { screens: Modal }, 21 }, 22 {initialRouteName: 'MainNavigation', mode: 'modal', headerMode: 'none'}, 23) 24 25 26type Props = {}; 27export default class App extends Component<Props> { 28 render() { 29 return ( 30 <NestNavigation /> 31 ); 32 } 33}
Main
1import React, {Component} from 'react'; 2import { Container, View, Header, Left, Body, Right, Button, Title, Text } from 'native-base'; 3 4type Props = {}; 5export default class Main extends Component<Props> { 6 push = () => { 7 const { navigation } = this.props 8 navigator.navigate('Push') 9 } 10 modal = () => { 11 const { navigation } = this.props 12 navigation.navigate('Modal') 13 } 14 render() { 15 return ( 16 <Container> 17 <Header> 18 <Left /> 19 <Body> 20 <Title>メイン</Title> 21 </Body> 22 <Right /> 23 </Header> 24 <View> 25 <Button small iconRight transparent primary onPress={this.push}> 26 <Text>プッシュ通知</Text> 27 </Button> 28 </View> 29 <View> 30 <Button small iconRight transparent primary onPress={this.modal}> 31 <Text>モーダル表示</Text> 32 </Button> 33 </View> 34 </Container> 35 ); 36 } 37}
Push
1import React, {Component} from 'react'; 2import { Container, Header, Left, Body, Right, Button, Icon, Title } from 'native-base'; 3 4 5type Props = {}; 6export default class Push extends Component<Props> { 7 render() { 8 return ( 9 <Container> 10 <Header> 11 <Left> 12 <Button transparent onPress={() => this.props.navigation.goBack()}> 13 <Icon name='arrow-back' /> 14 </Button> 15 </Left> 16 <Body> 17 <Title>プッシュ</Title> 18 </Body> 19 <Right /> 20 </Header> 21 </Container> 22 ); 23 } 24}
Modal
1import React, {Component} from 'react'; 2import { Container, Header, Left, Body, Right, Button, Icon, Title } from 'native-base'; 3 4 5type Props = {}; 6export default class Modal extends Component<Props> { 7 render() { 8 return ( 9 <Container> 10 <Header> 11 <Left> 12 <Button transparent onPress={() => this.props.navigation.goBack()}> 13 <Icon name='close' /> 14 </Button> 15 </Left> 16 <Body> 17 <Title>モーダル</Title> 18 </Body> 19 <Right /> 20 </Header> 21 </Container> 22 ); 23 } 24}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/02/17 07:40
2020/02/17 07:50
2020/02/17 07:58
2020/02/17 08:03