[英]Undefined is not an object (evaluating 'this.props.navigation.navigate') on React Native
I am currently working on my first react native project using Expo and I have a problem between the screens navigation where I get " undefined is not an object (evaluating 'this.props.navigation.navigate') ".我目前正在使用 Expo 处理我的第一个反应原生项目,我在屏幕导航之间遇到问题,我得到“未定义不是 object(评估 'this.props.navigation.navigate')”。 I want to know what is actually the problem and how can I fix it.
我想知道实际上是什么问题以及如何解决它。 Thank you.
谢谢你。 Here is the code for the screen where there is a navigation problem:
以下是出现导航问题的屏幕代码:
import {
StyleSheet,
Text,
View,
Button,
Date,
KeyboardAvoidingView,
} from "react-native";
import t from "tcomb-form-native";
import moment from "moment";
const Form = t.form.Form;
const User = t.struct({
Surname: t.String,
Name: t.String,
Birthday: t.Date,
});
const options = {
fields: {
Surname: {
label: "Surname",
},
Name: {
label: "Name",
},
Birthday: {
mode: "date",
label: "Birthday",
config: {
defaultValueText: "Click here to enter your birthday",
format: (date) => {
return moment(date).format("DD / MM / YYYY");
},
},
},
},
};
class Newform extends Component {
render() {
return (
<KeyboardAvoidingView behavior="padding">
<Text style={styles.setColorGreen} color="#8cba51">
Informations
</Text>
<Form ref="form" type={User} options={options} />
<Button
onPress={() => this.props.navigation.navigate("Chat")}
title="Next"
color="#8cba51"
/>
</KeyboardAvoidingView>
);
}
}
var styles = StyleSheet.create({
setColorGreen: {
color: "#8cba51",
alignItems: "center",
justifyContent: "center",
padding: 20,
fontWeight: "bold",
textAlign: "center",
fontSize: 20,
},
});
export default Newform; ```
You might not pass this component as screen component.您可能不会将此组件作为屏幕组件传递。 Can you please share your Navigator or share your higher level component that has this component in it?
您能否分享您的 Navigator 或分享包含此组件的更高级别的组件? The Navigator should look like this:
导航器应如下所示:
<Stack.Navigator>
<Stack.Screen name="NewForm" component={NewForm} />
<Stack.Navigator>
Or if you use this component inside a screen component you should pass navigation prop to child component like this或者,如果您在屏幕组件中使用此组件,您应该像这样将导航道具传递给子组件
// Stack Navigator
<Stack.Navigator>
<Stack.Screen name="NewForm" component={FormScreen} />
<Stack.Navigator>
class FormScreen extends Component {
render() {
return (
<NewForm {...this.props} />
);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.