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

131
Vistas
createAsyncThunks first promise is fulfilled, but subsequent promises are always rejected

I have a saveTrip function that is a redux async thunk. However, i am getting very weird behavior as only my first promise is resolved as "fulfilled" and every promise after that is "rejected"

export const saveTrip = createAsyncThunk(
    'trip/saveTrip',
    async (payload, thunkAPI) => {
        const trip = thunkAPI.getState().trip
        const result = await fetch(
            'http://localhost:5000/savetrip', {
            mode: 'cors',
            credentials: 'include',
            method: "post",
            body: JSON.stringify({ trip }),
            headers: {
                'Content-Type': 'application/json'
            },
        })
        const response = await result.json()
        return response
    }
)

Whats more unusual is that i stumbled upon a bandaid fix by implementing debounce like so :

export const saveTrip = createAsyncThunk(
    'trip/saveTrip',
    debounce(async (payload, thunkAPI) => {
        const trip = thunkAPI.getState().trip
        const result = await fetch(...)
        const response = await result.json()
        return response
    }, 5000)
)

Debounce doesnt actually "work" as i expect debounce to, but now, every promise is getting fulfilled with the expected data in the responses. Im pretty sure this is not a proper solution but I am very confused as to what's happening.

My goal is to just save my current state into my DB and i just call saveTrip whenever a reducer that changes my state is dispatched.

The error i get from the rejection in actions

about 4 years ago · Santiago Gelvez
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