'Difference between redux thunk and a promise

I just started learning about Redux, and I have a question about its purpose. According to what I know, redux-thunk delays the dispatch of an action, so in the code below, it waits until the server response before it dispatches. But isn't it the job of a promise. With my basic knowledge, the call-back inside then should only be called once we get the response anyway, right?

export const fetchRentalById = (rentalId) => {
  return dispatch => {  
    axios.get(`/api/v1/rentals/${rentalId}`)
    .then((rental) => {
      dispatch({
      type: FETCH_BY_ID,
      payload: rental.data
    })
  })
 }
}

So I tried removing the dispatch in return, and for some reasons it will dispatch in before the server response, but it doesn't seem to make sense to me. Thank you for reading. Call in component

const {rental, fetchRentalById} = props;
  let rentalId = props.match.params.id;
  useEffect(() => {
    fetchRentalById(rentalId);
  }, [ rentalId, fetchRentalById]);
...
const mapState = state => {
  return {
    rental: state.data.rental
  };
};
export default connect(mapState, {fetchRentalById})(RentalDetail);

I use mapDispatchToProps, so I don't need to use props.dispatch here.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source