2

saveProfile() does not return promise, although the person who has exactly the same code, the same function returns promise

  return async (dispatch, getState) => {
    const authUserId = getState().auth.id
    let data = await profileAPI.saveProfile(editDataAboutMe)
      if (data.resultCode === 0) {
      dispatch(setUserProfileThunkCreator(authUserId))
      return await Promise.resolve()
    } else {
      dispatch(stopSubmit('AboutMeEditForm', {_error: data.messages[0]}))
      return await Promise.reject()
    }
  }
}

mapDispatchToProps = (dispatch) => ({
      saveProfile: (editDataAboutMe) => {
        dispatch(saveProfileThunkCreator(editDataAboutMe))
     }
 }




const onSubmit = (editDataAboutMe) => {
    props.saveProfile(editDataAboutMe).then(() => {
      setEditMode(false)
    })
  }

1 Answers1

0

Assuming dispatch returns the thunk's return value (or a Promise thereof), fix the saveProfile function to return it as well:

mapDispatchToProps = (dispatch) => ({
    saveProfile: (editDataAboutMe) => {
        return dispatch(saveProfileThunkCreator(editDataAboutMe))
    }
})
DustInComp
  • 1,742
  • 8
  • 18
  • Thank you so much!!! It's working for me! I knew it was undefined somewhere, but for some reason I didn't think of that place... – SeeYou1ater Jul 20 '22 at 11:16