React: how to show progress of Axios during get request (not download or upload)
Here's what worked for me in React:
const client = axios.create({
baseURL: 'http://localhost:10000/v1/client',
timeout: 20000
})
let result = await client.get('/fetchMeSomething', {
onDownloadProgress: progressEvent => {
const total = parseFloat(progressEvent.currentTarget.responseHeaders['Content-Length'])
const current = progressEvent.currentTarget.response.length
let percentCompleted = Math.floor(current / total * 100)
console.log('completed: ', percentCompleted)
}
})
.then(res => {
console.log("All DONE: ", res.headers)
return res.data
})