I would like to get my users list with the api call and render a table with the data.
At the moment I can get the data but wen I try to display it, I have an error.
I think react is rendering before api call ends dont understand why.
Here is my code :
var Actions = Reflux.createActions([
"fetchList"
]);
Here is my store :
var bannersStore = Reflux.createStore({
users: { data : {}},
listenables: [Actions],
init: function() {
this.fetchList();
},
fetchList: function(){
var self = this;
reqwest({
url: 'http://localhost:9080/api/member.json',
method: 'get',
success: function (resp) {
console.log('fetch complete');
self.users = resp;
self.trigger({users :resp});
}
});
}
});
Here is my React class:
var Users = React.createClass({
getInitialState: function() {
return {users : UsersStore.fetchList()};
},
render: function() {
var usersRows = this.state.users.data.map(function(user, i) {
return (
<tr key={i}>
<td><Link to="user" params={{ id: user.id }}>{user.attributes.firstname + ' ' + user.attributes.lastname}</Link></td>
<td>{user.attributes.email}</td>
<td>{user.status}</td>
<td>{user.language}</td>
</tr>
)
});
return (
<div>
<table className="table table-striped">
<thead>
<tr>
<th>Name</th>
<th>Image</th>
<th>URL</th>
<th>Active?</th>
</tr>
</thead>
<tbody>
{ usersRows }
</tbody>
</table>
</div>
)
}
});
this.state.users.data
is undefind and I have an error (undefined).
Thank you for your help.