there. I have a question about using Axios for connecting apis. Here is the snippet of my code:
const [resData, setResData] = useState();
for(let i = 0; i < 5; i++) {
axios.put('api', params, config).then(res => setResData(prev => ({...prev, res.data.result})))
}
useEffect(() => {
if(resData.length === 5) {
axios.post('nextApi', {data: resData}, config)
}
}, [resData])
The logic is that I receive data from calling an api and I gather them and make a group and then I call the nextApi by sending the group of data I received from the previous api.
The problem is that I need to loop axios couple of times, so I tried to call the nextApi when receiving response, but failed. I currently only think of this way, but it looks kinda of complicated. I do not think I can understand my code in the future.
Is there a better way to complete the process?