Reactjs: I have been trying to build a ReactTable(npm ) from axios get request.The response data is in object of array format. So I can't populate my table .I am getting type-error : UN-handled Rejection (TypeError): resolvedData.map is not a function. I am aware the react table map cannot map over array of objects .I don't know how to map over and populate the table.
My axios.get request
componentDidMount(){
const url="http://localhost:5000/api/users/tenantView";
fetch (url,{
method: "GET"
}).then(response=> response.json()).then(usersList=>{
console.log((usersList)) ;
this.setState({
usersList : usersList
});
})
}
Here I am seeing the response in console,the data is being fetched correctly
{user: Array(5)}
user: Array(5)
0: {_id: "5d36f73f67665a1740620f55", name: "Pritam Kumar", email: "[email protected]", password: "$2a$10$ly84W9WLQr/Qih/AzN0PuOExctk5ohR9TxjtT.PUdsy4h6a9sY6pW", location: "Pune", …}
1: {_id: "5d36fc9c30ddd31638192498", name: "Raja", email: "[email protected]", password: "$2a$10$KC5i6EkDb5SIqaMQPh.RoumQON6PEYZIDE4TM1oTH6xhmOTaD.FOy", location: "Durgapur", …}
2: {_id: "5d3ac84a86688123789e13b2", name: "Puja", email: "[email protected]", password: "$2a$10$r17zOU1gTJvwoB.nBdRvi.qvDmsJhIlHbp//s8l0KEKgCEvbKoZAu", location: "Delhi", …}
3: {_id: "5d400d8f23eda427b0c020e0", name: "Goobi", email: "[email protected]", password: "$2a$10$sW/Cs32ouY2ZBPQ0sQK7YeRUNkdRfjucf/Y4ykiPbZRtXn49rm1rm", location: "Durgapur", …}
4: {_id: "5d492a271294110f64196b2c", name: "Imran", email: "[email protected]", password: "$2a$10$V5KWD60GrV1eNuOkDtTHVu9SjA2k6gshmwzWieYzJpus3fwhPWnbu", location: "Durgapur", …}
length: 5
__proto__: Array(0)
__proto__: Object
I have tried to map over by similar to this link but its not working React: Iterate over object, find array, and display array items
I have also tried to map in accessor like in react-table iterating over object array to print values in a column
I may be incorrect. Please have a look.Will these work ?
Render function
render() {
const columns =[
{
Header:"User ID",
accessor:"_id",
sortable: false,
filterable: false,
style:{
textAlign: "left"
},
width: 100,
maxWidth: 100,
minWidth: 100,
},
{
Header:"Name ",
accessor:"name",
filterable: false,
},
{
Header:"Email",
accessor:"email"
},
{
Header:"Password",
accessor:"password"
},
{
Header:"Farm",
accessor:"farm"
},
]
return(
<ReactTable
columns={columns}
data={this.state.usersList}
defaultPageSize={20}
>
</ReactTable>
);
}
}
Populate the table: No data is populated now.
this.state.usersList.userit looks like the data lives there.this.userList.useris not working @jsw324