无法读取属性' __ reactAutoBindPairs'未定义的 - React.js

时间:2016-07-04 18:03:23

标签: javascript node.js reactjs coffeescript

我试图用Coffeescript和Node在React中创建一个简单的组件。但是,它不断抛出这个错误:

Cannot read property '__reactAutoBindPairs' of undefined

这是我的代码:

index.coffee:

express = require('express')
JSX     = require('node-jsx').install()
React   = require('react')
TestApp = require('../components/Test.react')
router  = express.Router()

# home page
router.get '/', (req, res, next) ->
  React.renderComponent (TestApp {}), document.getElementById('test')
  res.render 'index', title: 'Example'

module.exports = router

Test.react.coffee:

React = require('react')

TestApp = React.createClass
    render: ->
      p "Hello!"

module.exports = TestApp

index.jade

extends layout

block content
  h1= title
  #test 
  p Welcome to #{title}

任何帮助将不胜感激。谢谢!

1 个答案:

答案 0 :(得分:3)

我认为你需要做一些事情:

  1. 安装ReactDOM包(npm install react-dom)。
  2. 需要ReactDOM。
  3. require()
  4. 中为您的组件包装React.createFactory()语句
  5. 使用ReactDOM.render()而不是React.renderComponent()渲染组件。
  6. 观察:

    express  = require('express')
    JSX      = require('node-jsx').install()
    React    = require('react')
    ReactDOM = require('react-dom')
    TestApp  = React.createFactory(require('../components/Test.react'))
    router   = express.Router()
    
    # home page
    router.get '/', (req, res, next) ->
      ReactDOM.render (TestApp {}), document.getElementById('test')
      res.render 'index', title: 'Example'
    
    module.exports = router
    

    请参阅the React blog以获取解释。