简体   繁体   English

反应Native Expo Uncaught Error'this.props = t'

[英]React Native Expo Uncaught Error 'this.props=t'

I am relatively new to the world of coding (1 year) and have just recently picked up react.js and react native. 我对编码世界比较陌生(1年),并且最近才开始使用react.js和react native。 When completing a react native tutorial, I stopped and then restarted my packager as my "app" had stopped live or hot loading. 完成React本机教程时,我停止了,然后重新启动了打包程序,因为我的“应用”已停止实时或热加载。 I had changed nothing in the code at this point from when it was working. 从工作开始到现在,我在代码中什么都没有改变。 Any help in fixing this error would be appreciated. 修复此错误的任何帮助将不胜感激。

I have already tried stopping and restarting both my packager from the expo and my emulator (genymotion). 我已经尝试停止并重新启动来自博览会和模拟器的打包程序(genymotion)。 I have also looked at the file paths to ensure I a`m running my packager in the same directory. 我还查看了文件路径,以确保我在同一目录中运行我的打包程序。

import React, { Component } from 'react';

export default class App extends Component {
  render(){
  return (
    <View style={styles.container}>
      <Text>Welcome to my FIRST React Native</Text>
    </View>
  );
 }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});

I then received an error message that read: 然后,我收到一条错误消息,内容为:

"Uncaught Error: undefined is not an object (evaluating 'this.props=t').

I expect this to produce the same error code mentioned above. 我希望这会产生与上述相同的错误代码。

The only issue I see is that Component should not be a function call. 我看到的唯一问题是Component不应是函数调用。 Try this 尝试这个

export default class App extends Component {
}

notice the '()' missing from the Component. 注意组件中缺少“()”。

I have noticed that you are extendind the Component class as a method, technically there is nothing wrong with that but it might cause conflicts, have you tried this instead: 我注意到您正在将Component类作为方法进行扩展,从技术上讲,这没有什么问题,但可能会导致冲突,请尝试使用此方法:

export default class App extends Component {
    // Your code 
}

You have not imported Text and View and StyleSheet... 您尚未导入Text and View和StyleSheet ...

import {Text, View, StyleSheet} from 'react-native'

You can then try it whether it works 然后,您可以尝试一下是否可行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM