I have a function that calls an end-point in my reactjs application. For network calls i have used axios. I want to implement a progressBar which actually shows the percentage of completion of end point calling. My function looks like this

export function createNewPost(postData) {

return dispatch => {
    dispatch(loading());
    axios.post(`${API_URL}/submit?u_id=${userId}&heading=${encodedHeading}`, data, token)
      .then(res => {
        const {response} = res.data;
        if (response === 200) {
          dispatch(redirect(`/closed_group/posts/${requestedId}`))
          } 
          else {
            dispatch(createPostRealNameSuccessNoPreview());
          }
        } 
      });
  }
}

I have found out i can do this using onUploadProgress in axios like this source

const config = {
    onUploadProgress: progressEvent => console.log(progressEvent.loaded)
}

axios.put('/upload/server', data, config)

But the problem i'm facing is because i'm using tokens i cannot use config since it will then become invalid number of arguements. How can i fix this?

0 Answers