I've spent a long time trying to figure out what is the exact problem. I have a react component that fetches an array of users from a service then store it in the component state but I had hardcode it here for simplicity. when I run my page nothing shows up with no signs of errors in the console. I'm a newbie to react please bear with me.
here is my component :
var usersTable = React.createClass({
getInitialState: function() {
this.state = {
users: [],
dataResponse: []
};
return this.state;
},
getData: function() {
component.state.dataResponse.push({
name: "john doe",
email: "john.d@outlook.com",
job: "production manager",
id: 882771
});
component.state.dataResponse.push({
name: "jane doe",
email: "jane.d@outlook.com",
job: "account manager",
id: 569811
});
//get the users from a service.
},
componentWillMount: function() {
this.getData();
if (this.state.dataResponse !== null && this.state.dataResponse !== undefined) {
var data = this.state.dataResponse;
for (var i = 0; i < data.length; i++) {
var tr = <tr>
<td> {
data[i].id
} </td> <td> {
data[i].name
} </td> <td> {
data[i].job
} </td> <td> {
data[i].email
} </td> </tr>;
this.state.users.push(tr);
}
}
},
render: function() {
return ( <table className = "table table-condensed"> {
this.state.users
} </table>);
}
});
ReactDOM.render( <usersTable /> , document.getElementById("usersComponentDiv"));
Plunk : https://plnkr.co/edit/CyYCgTArt7K5MLAbiCa7?p=preview