我试图用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}
任何帮助将不胜感激。谢谢!
答案 0 :(得分:3)
我认为你需要做一些事情:
npm install react-dom
)。require()
。React.createFactory()
语句
ReactDOM.render()
而不是React.renderComponent()
渲染组件。观察:
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以获取解释。