Home:ALL Converter>Calling API via redux in react app does not work

Calling API via redux in react app does not work

Ask Time:2020-01-14T07:39:27         Author:l3ftHand

Json Formatter

I am building a web app with MERN stack and using redux as the state management. I am now trying to load the data from mongoDB with my API and storing into redux before setting into react state. When calling the api with getShop() function directly from react app, the data is stored in react state and displayed in the app. However it does not work when i am trying to use it through redux as per my below codes. There are no errors, but just not loading any information.

Action:

load : () => {
       let thunk = (dispatch) => {
           api.getShops()
           .then(res => {
               let barbershops = res.data
               dispatch(barberFactory.set(barbershops))
           })
       }
       return thunk
   },

calling from react app:

function mapDispatchToProps(dispatch){
  return {
    loadBarber : () => {
      dispatch(barberFactory.load)
    },
  }
}

The function is called at componentDidMount()

Author:l3ftHand,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/59725728/calling-api-via-redux-in-react-app-does-not-work
yy