Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

130
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!