1

Error: state.Array.slice is not a function

Code where the error occurs:

    const initialState: IUserProfileState = { 
      useremail: '',
      status: '',
      //items: {} as IListItem[],
      EmpID: '',
      ExeArray : {} as IArrayItem[],
      arrayIndex: 0,
      userProfileItems: {} as IUserProfile,
    }
    
    export const reducer = (state: IUserProfileState = initialState, action) =>  {
        switch (action.type) {
        case INPUT_UPDATE:
          console.log(action.payload);
          const { field, value } = action.payload;
          var ExeArray = [...state.ExeArray]  //Error on this line
          switch(field) {
            case 'a' :
              ExeArray[state.arrayIndex] = {...ExeArray[state.arrayIndex], a: value};
              return;
            case 'b' : 
              ExeArray[state.arrayIndex] = {...ExeArray[state.arrayIndex], b: value};
              return;
            case 'c' : 
              ExeArray[state.arrayIndex] = {...ExeArray[state.arrayIndex], c: value};
              return;
            default :
              return;
          }
        default:
          return state; 
   }}; 
   export default reducer;

a b c ... inside textboxes are hardcoded values. when I try to enter any value inside the textbox I get this error.

I am trying to update the props whenever there is textchange.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.