sau*_*ton 17 javascript android react-native
新的反应原生用户在这里.我遇到了一个问题,我不知道该怎么办.我能够正常运行react-navigation,然后开始收到一个错误:"路由的组件必须是一个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>
);
}
}
Run Code Online (Sandbox Code Playgroud)
任何帮助/反应指针非常感谢.谢谢!
A-J*_*J-A 39
我认为问题在于home.js,因为你没有导出它.试试这个 :
export default class Home extends Component { ... }
^^^^^^^^^^^^^^
Run Code Online (Sandbox Code Playgroud)
添加或添加
export default Home;
Run Code Online (Sandbox Code Playgroud)
在home.js
文件的末尾
小智 5
const MyNavigator = createStackNavigator({
RouteNameOne: {
screen: () => <HomeScreen/>
},
RouteNameTwo: {
screen: () => <NewScreen/>
}
}, {
initialRouteName: 'RouteNameOne'
});
Run Code Online (Sandbox Code Playgroud)
它会起作用。
归档时间: |
|
查看次数: |
19407 次 |
最近记录: |