简体   繁体   English

Undefined 不是 React Native 上的 object(评估“this.props.navigation.navigate”)

[英]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.

相关问题 【React-native】undefined不是对象(评估&#39;_this.props.navigation.navigate&#39;) - 【React-native】undefined is not an object (evaluating '_this.props.navigation.navigate') undefined 不是一个对象(评估&#39;this.props.navigation.navigate&#39;)-React Native - undefined is not an object (evaluating 'this.props.navigation.navigate') - React Native 未定义(评估&#39;this.props.navigation.navigate&#39;)React Native - undefined (evaluating 'this.props.navigation.navigate') React Native React Native:React Navigation StackNavigator 不工作。 得到错误:“未定义不是一个对象(评估&#39;this.props.navigation.navigate&#39;)” - React Native: React Navigation StackNavigator not working. Getting error: “undefined is not an object (evaluating 'this.props.navigation.navigate')” react-native-navigation给出错误“未定义不是对象(评估&#39;_this.props.navigation.navigate&#39;)” - react-native-navigation giving error “undefined is not an object (evaluating '_this.props.navigation.navigate')” undefined 不是 object(评估 'this.props.navigation.navigate') - 基于函数方法的导航时 React Native - undefined is not an object (evaluating 'this.props.navigation.navigate') - React Native while navigation based on functions approach 未定义不是对象(评估this.props.navigation.navigate) - undefined is not an object (evaluating this.props.navigation.navigate) 未定义不是对象(评估&#39;_this.props.navigation.navigate&#39;) - undefined is not an object (evaluating '_this.props.navigation.navigate') React Native - 导航问题“未定义不是对象(this.props.navigation.navigate)” - React Native - navigation issue “undefined is not an object (this.props.navigation.navigate)” 反应本机导航(未定义不是对象.. this.props.navigation.navigate - React native navigation (undefined is not an object .. this.props.navigation.navigate
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM