2021年4月24日星期六

Reducer return undefined in data update

I am trying to create a reducer to delete object after an action has invoked, but i cant update and save the new object inside my data

Reducer:

export default function deleteCard(state = INITIAL_STATE, action: any) {    if (action.type === 'DELETE_CARD') {      return state.data.filter((card: Card) => card.cardId !== action.id)    } else {      return state    }  }  

Initial State:

  export const INITIAL_STATE = {    activeCard: 0,    data: [      {        cardId: 0,        cardName: 'Credit card',        cardUsername: 'Vanzo',        cardNumber: '1234 1234 1234 1234',        hideCardNumber: false,      },    ]  }  

Following error when i try to update:

TypeError: undefined is not an object (evaluating 'state.data.filter')    
https://stackoverflow.com/questions/67248848/reducer-return-undefined-in-data-update April 25, 2021 at 09:04AM

没有评论:

发表评论