【问题标题】:React Native error: undefined is not a functionReact Native 错误:未定义不是函数
【发布时间】:2017-12-28 17:29:52
【问题描述】:

我开始学习 React Native。我正在学习教程并编写了以下代码:

var React = require('react-native');

var {
  Text,
  View,
  AppRegistry
} = React;

var StopWatch = React.createClass({
  render: function() {

  }
});

AppRegistry.registerComponent('stopwatch', function() {
  return StopWatch;
});

但是,我收到了这个错误:

undefined is not a function (evaluating 'React.createClass({displayName:'StopWatch', 
render:function render() {}
})')

我在 Android 模拟器中运行 React Native,使用命令

react-native run-android

文件是

App.js

【问题讨论】:

    标签: android react-native ecmascript-6


    【解决方案1】:

    这并不能真正回答您的问题,但为什么要使用已弃用的语法这样做呢?

    在此处尝试 facebook react-native 教程:https://facebook.github.io/react-native/docs/tutorial.html

    或者更好的是,使用美妙的create-react-native-app

    这应该让你启动并运行

    【讨论】:

    • 啊,好的,谢谢。我正在关注我在 udemy 上购买的教程,并且该课程可能是不久前制作的。代码的哪些部分被弃用了?
    • React.createClass 已被弃用,React 世界中几乎每个人现在都只使用 es6。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-06
    • 2019-03-14
    相关资源
    最近更新 更多