Morgan Allen Morgan Allen - 21 days ago 5
React JSX Question

React: Calling methods inside a variable

I'm trying to run a simple React component and not sure why this isn't working.

For some reason,

addRows
isn't running. Can someone explain why?

var CreateRows = React.createClass({
addRows : function(){
return (
<tr>
<td>Morgan</td>
<td>test@gmail.com</td>
</tr>

)
},

render: function(){
return (
<tbody>
{this.addRows}
</tbody>
)
}
});

Answer

You have to call the function with { this.addRows() }. With your code you are only referring to the function but not invoking it. Such a statement could be used for defining a function e.g. like onClick={ this.addRows }