I am new to React and Node Js and I am currently facing this problem of not being able to store data received from axios, which is inside a map() function.
const [novelArray,setNovelArray] = useState([]);
const item_array = [];
useEffect(async () => {
//GET DATASET OF USERS WITH RATING
const request1 = await axios.get(
"http://localhost:5000/recommendation-object"
);
const response1 = request1.data;
//SEND DATA FROM RESPONSE1 TO REQUEST2 AND GET ITEM RECOMMENDATION LIST FOR CURRENT USER
const request2 = await axios.post("http://localhost:5000/recommendation-algorithm",
{
data: response1,
user1: "user123"
}
);
const response2 = request2.data;
//MAP ARRAY ITEM AS ITEM_ID FROM RESPONSE2 , POST AND RECEIVE ITEM_NAME
response2.map(async (x) => {
const request3 = await axios.get(`http://localhost:5000/novels/${x[0]}`);
const response3 = request3.data[0];
item_array.push(response3);
// setNovelArray(item_array);
});
setNovelArray(item_array);
}, []);```