Cuando llamo a otra acción asíncrona en una acción asíncrona, devuelve un error. ¿¿¿Cómo arreglar este error??? Yo uso redux-thunk
Esta es la primera acción que solicita a un servidor que obtenga una matriz de objetos (calendarios)
getCalendars: () => async (dispatch: AppDispatch, getState: GetState) => { try { const { token } = getState().authReducer; const res: AxiosResponse<{ calendars: Calendar[] }> = await axios.get( "http://26.193.135.145:8000/api/calendars/", { headers: { Authorization: `Bearer ${token}`, }, } ); dispatch(CalendarActionCreators.getCalendarsSuccess(res.data.calendars)); } catch (error: any) { const err: AxiosError = error; dispatch( CalendarActionCreators.getCalendarsError(err.response?.data.message) ); console.log(err.response?.data.message); } }Aquí está la segunda acción que envía un objeto recién creado (calendario) al servidor, y para agregar un nuevo calendario a la lista, volvemos a enviar la solicitud al servidor llamando a la acción anterior.
createCalendar: (title: string, description: string) => async (dispatch: AppDispatch, getState: GetState) => { try { const newCalendar: CalendarObject = { title, description }; console.log(newCalendar); const { token } = getState().authReducer; const res: AxiosResponse = await axios.post( "http://26.193.135.145:8000/api/calendars/", newCalendar, { headers: { Authorization: `Bearer ${token}`, }, } ); if (res.status === 200) { // here is an error //dispatch(CalendarActionCreators.getCalendars()); } } catch (error: any) { const err: AxiosError = error; dispatch( CalendarActionCreators.createNewCalendarError( err.response?.data.message ) ); console.log(err.response?.data.message); } },