D
D
dfv1232018-02-04 23:04:16
React
dfv123, 2018-02-04 23:04:16

Why is there an error on the delete action?

Help me fix the error with the delete action I can't imagine what's wrong.
https://codesandbox.io/s/k5z5z46zl3

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2018-02-04
@dfv123

You set an initial initial state like this: And then you try to call the filter array method on it when the state is an object. Fix the reducer like this:

const reducer = (state = { tweets: tweets.data }, action) => {
  switch (action.type) {
    case 'DELETE': {
      return {
        ...state,
        tweets: state.tweets.filter(value => value.id !== action.id),
        };
    }
    default:
      return state;
  }
};

Demo: https://codesandbox.io/s/n5wlj8wq34

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question