【问题标题】:Uncaught TypeError: TodoList is not a function未捕获的 TypeError:TodoList 不是函数
【发布时间】:2016-08-07 22:42:12
【问题描述】:

我是 React 的新手,所以也许专家会很快发现问题。这是我的router.js

define(["backbone", "react", "jsx!view/todoList"], function(Backbone, React, ReactDOM, TodoList) {
  return Backbone.Router.extend({
    routes : {
      "" : "index"
    },
    index : function() {
      console.log("hello world");

      var todos = new Backbone.Collection([
        {
          text: 'Dishes!',
          dueDate: new Date()
        }
      ]);

      React.render(<TodoList todos={todos} />, document.body);
    }
  });
});

我在控制台中收到以下错误:VM7282:19 Uncaught TypeError: TodoList is not a function

也许问题在于已弃用的 JSXTransformer (https://facebook.github.io/react/blog/2015/06/12/deprecating-jstransform-and-react-tools.html)。建议改用 Babel(在我的情况下,而不是 jsx!view/todoList 来使用 babel!view/todoList)。我遇到的问题是从哪里导入 babel.js。这里http://facebook.github.io/react/docs/displaying-data.html 他们导入https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23/browser.min.js 但是当我做同样的事情时 babel!view/todoList 不起作用。

【问题讨论】:

    标签: reactjs react-router jsx babeljs require


    【解决方案1】:

    这可能比 React 更像是一个 Backbone 问题。我对 Backbone 不熟悉,但对于 React,这通常是因为您正在尝试使用一些尚未正确导入或定义的组件。

    例如,您可能正在尝试这样做:

    React.render(<TodoList todos={todos} />, document.body);
    

    没有正确导入var TodoList = require('./TodoList')

    或实际创建组件。

    var TodoList = React.createClass({ 
        render: function() {
        // code code code code
      }
    })
    

    我认为这很可能是问题所在: https://medium.com/react-tutorials/react-backbone-router-c00be0cf1592#.q4bsdqqgr

    【讨论】:

    猜你喜欢
    • 2017-07-20
    • 2019-09-26
    • 2015-12-29
    • 2021-09-09
    • 2017-07-31
    • 2016-11-02
    • 2022-01-25
    • 2016-11-21
    • 2021-03-13
    相关资源
    最近更新 更多