0

I encountered a problem cannot solve it anyhow. Given this API call with url parameters. The component should fetch new data as soon as the parameter changed. So, if the date is changing redux should call this function again with the new date and show the new data.

My code is in the action.js:

 export const getSingleDoctorAppointments = (clinicId, doctorId, date, 
  appointmentTypeId) => dispatch => {
 if (date !== null && date !== undefined) {
    const url = `${apiAddress}DoctorAppointment?clinicId=${clinicId}&doctorId=${doctorId}&date=${date.getDate() +
        '/' +
        (date.getMonth() + 1) +
        '/' +
        date.getFullYear()}&appointmentTypeId=${appointmentTypeId}&insuranceType=&overview=true`;

    axios
        .get(url)
        .then(res =>
            dispatch({
                type: GET_SINGLE_DOCTOR_APPOINTMENTS,
                payload: res.data
            })
        )
        .then(
            dispatch({
                type: PROFILE_LOADING,
                payload: 'Loading Profile'
            })
        )
        .catch(err =>
            dispatch({
                type: GET_SINGLE_DOCTOR_APPOINTMENTS,
                payload: null
            })
        );
}
};

After this function, call I would like to fetch the new data with the new parameters:

export const getSelectedDate = date => dispatch => {
dispatch({
    type: GET_SELECTED_DATE,
    payload: date
});
};

I have tried componentWillRecieveProps inside the component itself. Was not working. I hope it is understandable. I guess it is because of asynchronous and synchronous calls.

dpapadopoulos
  • 1,748
  • 4
  • 20
  • 29

0 Answers0