我尝试使用React和Node来创建应用程序。但是,我在使用其他组件创建组件时遇到问题,然后将其渲染到#34; master"零件。在Components.js文件中,我定义了多个组件,如:
/** @jsx React.DOM */
var React = require('react');
var ReactDOM = require('react-dom');
var Component = require('../components/Component');
class Comp1 extends React.Component {
render() {
return (
<div>
some stuff here
</div>
)
}
};
...
module.exports = Master = React.createClass({
render: function() {
return (
<div>
<Comp1 />
<Comp2 />
</div>
)
}
});
然后,在我的routes.js中,我有:
var JSX = require('node-jsx').install();
var React = require('react');
var ReactDOM = require('react-dom/server');
var Component = require('./components/Component');
module.exports = {
index: function(req, res) {
var markup =
ReactDOM.renderToString(React.createElement(Component));
res.render('home', {
markup: markup
});
}
};
在我的app.js中,我有:
/** @jsx React.DOM */
var React = require('react');
var Component = require('./components/Component');
ReactDOM.render(
<Component />,
document.getElementById('root')
);
我认为我错误地将组件嵌套在Master中,然后错误地导出Master,因为我收到错误消息&#34; TypeError:类构造函数Comp1无法在没有&#39; new&#39;& #34 ;.我不太清楚该怎么做;任何帮助将不胜感激,谢谢!