I am using react.js as the templating library in my node.js application . I am using jsx syntax for my react components. I have a route like /entities which renders the entities.jsx file (it is a view) . I have the following code in my entities.jsx file. I am trying to call the onclickhandler in my code and its not working.I am not rendering it explicitly using React.render but the component is showing in the browser when I hit localhost:/entities but the onclick handler isnt firing.
var MyComponent = React.createClass({
alertMessage: function() {
alert(this.props.name);
},
render: function () {
return (
<div onClick={this.alertMessage}>
Hello {this.props.name}
</div>
);
}
});
The examples that I have seen online render a jsx script embedded inside an html and a component rendered inside an html div tag but I am trying to use react.js in my node.js application. I dont want to render it inside an html tag but the component should render based on a url and should be dynamic
I have the following code snippet in my index.js file in my node application . I hit the view 'entities' through my index.js file that renders the view entities.
app.get('/entities', function(req, res) {
res.render('entities', {
title: 'Entities - Turkey Disclosure',
name: 'Entities',
selection: 'header-entities'
});
});