Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

126
Vistas
Tell me how to call another asynchronous action in one asynchronous action?

When I call another asynchronous action in an asynchronous action, it returns an error. How to fix this error??? I use redux-thunk

Here is the first action that requests a server to get an array of objects (calendars)

    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);
        }
      }

Here is the second action that sends a newly created object (calendar) to the server, and to add a new calendar to the list we re-send the request to the server by calling the previous action.

    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);
          }
        },
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda