Currently tackling a challenge in my React timesheet application. I am facing an issue while attempting to submit multiple entries simultaneously. Each entry requires its own API call, which is causing some trouble in the process. Here's what I have set up so far within a redux Thunk context:
var foo = new Promise((resolve, reject) =>{
timesheets.forEach(timeentry => {
api_function = 'XXXXXX' // string for submitting 1 entry
axios.post(url, api_function);
}
})
The plan is to execute another call once all entries are posted to refresh the timesheet data displayed on the frontend. However, I've encountered an issue where not all posts go through successfully; only 2-3 at most.
I've conducted some console logging to verify that the forEach loop runs the correct number of times and that the api_function string contains the accurate data during each iteration.
The problem lies in understanding why certain entries post successfully while others do not. It doesn't seem to follow any specific pattern as even seemingly random entries either go through or fail.
If there's a more effective approach to address this issue, suggestions would be greatly appreciated. In essence, seeking a method to carry out a series of POST API calls, ensuring completion before making a GET call to update the data.