I cannot define my state in reduxjs/toolkit as Array

Viewed 18

I need to define in my app state as empty Array initially and later it will be an Array of objects.

I have object type defined like below:

export type LuxmedBenefitUserType= {
  id: number;
  name: string;
  lastName: string;
  profileName: string;
  contractForm: string;
  userRelation: string;
  offerType: string;
  totalPrice: number;
  employerCost: number;
  employeeCost: number;
};

Then I define createSlice initial state as below.

export const addEditLuxmedBenefitSystemsSlice = createSlice({
  name: 'addEditLuxmedSlice',
  initialState: [] as LuxmedBenefitUserType[],
  reducers: {
    addEditBenefits: (state, action) => {
      const {id} = action.payload;
      if(!state) {state.push(action.payload)};
      if(state) {state.map = (user)=>{
    user.id === id && return action.payload
  }}; 
    },
  },
});

But with this I cannot procee with .push , it throws me an error :

any
Property 'push' does not exist on type 'never'.

Can You please let me know what I do wrong here and that state will allow me to use .push method ?

thanks

0 Answers
Related