gpt4 book ai didi

javascript - React Native Navigation 组件路由问题

转载 作者:IT老高 更新时间:2023-10-28 23:38:44 30 4
gpt4 key购买 nike

这里有新的 react 本地用户。我遇到了一个问题,我不确定如何继续。我能够让 react-navigation 正常运行,然后开始收到错误消息:“路由组件必须是 React 组件”,但除非我遗漏了什么,否则我相信我引用的组件 一个 react 组件。请参阅下面的 index.android.js 和下面的 Home.js:

//index.android.js
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View
} from 'react-native';
import {
TabNavigator,
StackNavigator
} from 'react-navigation';

import Home from './app/components/Home/Home';
import Search from './app/components/Search/Search';

export default class demoApp extends Component {
render() {
return (
<SimpleNavigation/>
);
}
}

export const SimpleNavigation = StackNavigator({
Home: {
screen: Home,
header: { visible: false },
navigationOptions: {
title: 'Home',
header: null
},
},
Search: {
screen: Search,
navigationOptions: {
title: 'test'
},
},
},{});


//Home.js
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
Image,
TextInput,
Button,
TouchableHighlight
} from 'react-native';

class Home extends Component {
constructor(props){
super(props);
this.state = {zipCode: ''}
}
navigate = (zipCode) => {
this.props.navigation.navigate('Search', zipCode);
}
render() {
return (
<View style={styles.container}>
<View style={[styles.boxContainer, styles.boxOne]}>
<Image style={styles.logo} source {require('../../images/Logo.png')} />
<Text style={styles.title}>An application to do things</Text>
<TextInput
style={styles.textInput}
placeholder='Enter a Zip Code'
onChangeText={(zipCode) => this.setState({zipCode})}
>
</TextInput>
</View>
<View style={[styles.boxContainer, styles.boxTwo]}>
<TouchableHighlight onPress={() => this.navigate(this.state.zipCode)}>
<Text style={styles.searchBox}>
Search
</Text>
</TouchableHighlight>
</View>
</View>
);
}
}

enter image description here

非常感谢任何帮助/ react 指针。谢谢!

最佳答案

我认为问题出在 home.js 因为您没有导出它。试试这个:

export default class Home extends Component { ... } 
^^^^^^^^^^^^^^

添加这些或只是添加

 export default Home; 

home.js 文件的末尾

关于javascript - React Native Navigation 组件路由问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44749682/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com