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

153
Views
How to pass the object to action in slice?

I need to pass userId and userNickname to action authUser in authSlice reducer.

authSlice:

import { createSlice } from '@reduxjs/toolkit';

const initialState = {
    userId : null,
    userNickame : "",
    isAuth : false,
    isAdmin : false, 
}

export const authSlice = createSlice({
    name : 'auth',
    initialState,
    reducers : {
        authUser : (state, action) => {
            //const {userId, userNickame} = action.payload;
            state.userId = userId;
            state.userNickame = userNickame;
            state.isAuth = true;
        },
    },
})

export const { authUser } = authSlice.actions
export default authSlice.reducer

calling dispatcher

//...

const dispatch = useDispatch();
const userId = useSelector((state) => state.userId);
const userNickname = useSelector((state) => state.userNickname);

//...

dispatch(authUser(/* I need to pass userId and userNickname here */));
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Simply

dispatch(authUser({ userId, userNickname }));

which is equivalent to

dispatch(authUser({ userId: userId, userNickname: userNickname }));

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!