我想在index.ios
文件的Navigator
中使用另一个文件夹中名为EnterName
的组件.当我在同一个文件中输入EnterName
时,我没有遇到任何问题,但当我try 从另一个文件导入它时,我得到:
Element type is invalid: expected a string (for built-in components
or a class/function (for composite components) but got: undefined.
Check the render method of `Navigator`
我try 了两种导入EnterName组件的不同方法,但都不起作用:
import {EnterName} from './App/Components/EnterName';
var EnterName = require('./App/Components/EnterName');
下面是一些使用Navigator
并试图从另一个文件夹中使用组件EnterName
的文本(当在同一个文件中声明EnterName时,这一点有效).
render() {
return (
<Navigator
initialRoute={{name: 'Name entry', index: 0}}
renderScene={(route, navigator) =>
<EnterName
name={route.name}
onForward={() => {
var nextIndex = route.index + 1;
navigator.push({
name: 'Scene ' + nextIndex,
index: nextIndex,
});
}}
onBack={() => {
if (route.index > 0) {
navigator.pop();
}
}}
/>
}
/>
);
}
}
如果您想查看EnterName文件,请点击这里:
import React, {
Text,
View,
Component,
Image,
StyleSheet
} from 'react-native';
class EnterName extends Component {
render() {
return (
<View style={styles.center}>
<View style={styles.flowRight}>
<TextInput style={styles.inputName}
placeholder="Enter your name"
textAlign="center"
onChangeText={(text) => this.setState({text})}
//value={this.state.text}
/>
<TouchableHighlight style={styles.button}
underlayColor='#99d9f4'>
<Text style={styles.buttonText}> Go </Text>
</TouchableHighlight>
</View>
</View>
)
}
}
// The stylesheet is here, and then below it I have:
module.export = EnterName;
你能帮我找出如何模块化我的代码吗?
EDIT: I just forgot the "s" at the end of module.exports. Seems like export default class _classname extends Component { is the way to go.