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

129
Views
redux toolkit state is not changing

When I send request I got my data back in json and I can see it when console.log(). But when I try to change my state, it's not changing. Can you guys please help me to understand why? Don't judge too hard I am still learning. Thank you

Here is my code

export const login = createAsyncThunk(
     'auth/login',
     async (user) => {
          try {
               const response = await loginUser(user);
               console.log(response.data) /// data present
               return response.data
          } catch (error) {
               console.log(error)
          }
     }
)

export const authSlice = createSlice({
     name: 'auth',
     initialState: { user: {}, status: '', message: '', success: false, error: '' },
     reducers: {
          [login.pending]: (state, action) => (
               state.status = 'loading'
          ),
          [login.fulfilled]: (state, { payload }) => {
               state.user = payload.user
               state.status = 'success'
               state.message = payload.message
               state.success = true
               state.error = ''
          },
          [login.rejected]: (state, { payload }) => {
               state.user = payload
               state.status = 'failed'
               state.success = false
               state.error = payload
          }
     }
})
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You need use the extraReducers with builder, something like that :

reducers: {
    //something, we don't care it
  },
  extraReducers: (builder) => {
    builder.addCase(login.pending, (state) => {
      state.status = what you want
    });
    builder.addCase(login.fulfilled, (state) => {
      blabla
    });
    ... and again and again 
  },

see https://redux-toolkit.js.org/api/createAsyncThunk (all is on the doc, no better source for RDK)

about 4 years ago · Juan Pablo Isaza Report
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!