为什么我有一个错误“无法读取未定义的属性”地图”?

我正在使用React + Redux,我想创建一个点赞计数器,但出现错误“无法读取未定义的属性”地图”。

我的减速器代码:

const initialState = {
    comments: [],
    text: ''
}


case PUT_LIKE: {
        return {
           ...state,
           comments: state.comments.id === action.id ? state.comments.like + 1 : state.comments.like 
      }
}

//before this I have this case for posting comments

 case ADD_COMMENT: {
            let newComment = {
                id: shortid.generate(),
                text: state.text,
                like: 0,
                dislike: 0,
                rating: 0
            }
            return {
                ...state,
                comments: [newComment, ...state.comments],
                text: ''
            }
        }

我的组件的代码(删除了一些代码以使其更容易):

const ClientFeedback = ({comments,text,postComment,onCommentChange,putLike}) => {

    return (

                      <div className='comments-container'>
                    {comments.map(m => 
                    <div key={m.id} className='comment-container'>
                        <div className='name'>
                            {nameImg}John
                            <span className='product-rating'>{rating}{rating}{rating}</span>
                            <SetDate />
                        </div>
                        <div className='text-comment'>
                            <span onClick={putLike} className='like'>{like}{m.like}</span>
                            <span className='dislike'>{dislike}{m.dislike}</span>
                            <div className='text'>{m.text}</div>
                        </div>
                    </div>)}
                </div>
    )
}

评论