小编CHB*_*ser的帖子

React Redux意外的令牌,预期","

我正在使用React with react-redux和redux-actions.

我有以下减速机一直告诉我

意外的令牌,预期","

但我不确定为什么.

comments.js (reducer):

import { handleActions } from "redux-actions";
import {
  GET_COMMENTS,
  SET_COMMENTS,
  ADD_COMMENT
} from "../constants/actionTypes";

export default handleActions(
  {
    [GET_COMMENTS]: (state, action) => state,
    [ADD_COMMENT]: (state, action) => {
      const comments = {
        ...state.comments,
        action.payload
      };
      return {
        ...state,
        comments
      };
    },
    [SET_COMMENTS]: (state, action) =>
      Boolean(action.payload) ? action.payload : state
  },
  {}
);
Run Code Online (Sandbox Code Playgroud)

导致麻烦的动作是ADD_COMMENT.我尝试过以下几种方法:

[ADD_COMMENT]: (state, action) => {
  ...state,
  comments: {
    ...state,
    action.payload
  }
}
Run Code Online (Sandbox Code Playgroud)

要么

[ADD_COMMENT]: (state, action) …
Run Code Online (Sandbox Code Playgroud)

reactjs redux react-redux redux-actions

2
推荐指数
1
解决办法
221
查看次数

标签 统计

react-redux ×1

reactjs ×1

redux ×1

redux-actions ×1