I'm fetching data using axios as the following :
{
"data": {
"3": {
"id": 4,
"value": "FaAlgolia",
"name": "zaefzaef",
"profile_id": 4,
"order": 9000,
"created_at": "2021-05-17T20:25:03.000000Z",
"updated_at": "2021-05-17T20:25:03.000000Z",
"url": "katon",
"profile": {
"id": 4,
"username": "xxxxxxxxx",
"bio": "zfzefzef",
"preview": "ssss",
"address": "zefzef",
"country": "us",
"p_color": "#ffffff",
"s_color": null,
"logo": "afffable",
"showlogo": "null",
"selectedOption": "option2",
"url": "katon",
"user_id": 2,
"created_at": null,
"updated_at": "2021-05-17T20:28:08.000000Z"
}
},
"4": {
"id": 5,
"value": "FaAlipay",
"name": "azdadzzad",
"profile_id": 4,
"order": 9000,
"created_at": "2021-05-17T20:41:53.000000Z",
"updated_at": "2021-05-17T20:41:53.000000Z",
"url": "katon",
"profile": {
"id": 4,
"username": "xxxxxxxxx",
"bio": "zfzefzef",
"preview": "ssss",
"address": "zefzef",
"country": "us",
"p_color": "#ffffff",
"s_color": null,
"logo": "afffable",
"showlogo": "null",
"selectedOption": "option2",
"url": "katon",
"user_id": 2,
"created_at": null,
"updated_at": "2021-05-17T20:28:08.000000Z"
}
}
}
}
In React :
const [list, setList] = React.useState([]);
useEffect(() => {
axios
.get("http://localhost:8000/api/social/profile/katon")
.then((response) => {
let test = (response.data.data)
setList(test)
})
.catch((err) => console.log(err));
}, []);
I know that I have a problem with the received array, I tried adding [] but none of that worked.
I searched React code throwing “TypeError: this.props.data.map is not a function” & React JS - Uncaught TypeError: this.props.data.map is not a function and didn't find my answer.