Here is the code
class Users extends Component {
constructor(){
super();
this.state={users:[]};
}
componentDidMount(){
fetch('http://some_ip_address/api/subuserlist',{
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'filterfield': 'group_id',
'filtervalue': 'random_filter_value'
}
}).then(result=>result.json())
.then(function(data) {
//console.log(data); //able to print data
this.setState({users:data});
}, () => {
if (this.state.users.length > 0) {
console.log(this.state.users[0].firstName);
}else{
console.log('in else'); // going to else
}
})
.catch(function(error) {
// If there is any error you will catch them here
});
}
render() {
return (
<tbody>{this.state.users && this.state.users.map(function(users) {
return (
<tr>
<td>{users.firstName}</td>
</tr>
)
})}</tbody>
);
}
}
export default Users;
Can some body help? Am not getting any data in this.state.users