Bolboa Bolboa - 5 months ago 11
Node.js Question

react function not being called

I am rendering a react class using node js as so...

var express = require('express');
var router = express.Router();

var React = require('react');
var reactDom = require('react-dom/server');
var App = React.createFactory(require('../components/index'));

router.get('/', function(req,res) {
var reactHtml = reactDom.renderToString(App({}));
res.render('../../tutorHub/views/index.jade', {reactOutput: reactHtml});
module.exports = router;

The page gets rendered fine, but no function that I add gets called. For example, in my

class App extends React.Component {
constructor(props) {
getClass() {
return "a_class";

render() {
return (
<div className={this.getClass}></div>

module.exports = App;

function is not called. Instead the className becomes the code

class = getClass() {
return "a_class";

instead of simply
when I check the html. For some reason, rather than the function being called, it is simply saved as a string and placed in to the className.

Why is this happening? I am not able to call any functions I make. Can someone help me out?


The function isn't called because you didn't call it. You can see the function's source, because any function that gets coerected to a string will do the same ((""+(foo=>bar)) === "foo=>bar"). All you have to do is:

<div className={this.getClass()}></div>