I am still in progress of learning Reactjs.
I am trying to populate table headers within a table row.
Somehow the code written below is treating the generated table headers via the renderTableHeaders() function as pure text only.
module.exports = React.createClass({
getInitialState: function() {
return {
defaultTableHeaders: [
'a', 'b', 'c', 'd',
]
}
},
renderTableHeaders: function() {
var markup = [];
var defaultTableHeaders = this.state.defaultTableHeaders;
for (var index = 0; index < defaultTableHeaders.length; index++) {
markup.push('<th>' + defaultTableHeaders[index] + '</th>');
}
return markup;
},
render: function() {
return (
<thead>
<tr>
{this.renderTableHeaders()}
</tr>
</thead>
);
}
});
When I modify the render() function to below then it would work properly. Any idea why?
render: function() {
return (
<thead>
<tr>
<th>a</th><th>b</th><th>c</th><th>d</th>
</tr>
</thead>
);
}