D
D
Dmitry2019-04-24 09:51:51
React
Dmitry, 2019-04-24 09:51:51

How to add state to reducer.js?

Hello, in the reducer, when adding a comment to the list of comments, I do this:

case ADD_PRODUCT_COMMENT:
            return {
                ...state,
                allComments: [...state.comments.allComments, action.payload],
            };

but when adding allComments is not updated but adds updated allComments next to comments
5cc00732ce8cc554243271.png
How to do it right? To update the existing allComments.
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2019-04-24
@ddimonn8080

case ADD_PRODUCT_COMMENT:
  return {
    ...state,
    comments: {
      ...state.comments,
      allComments: [
        ...state.comments.allComments,
        action.payload,
      ],
     },
  };

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question