期望一个赋值或函数调用,而是在switch语句中看到一个表达式 - React js

问题描述 投票:0回答:1

我有一个reducer,它有switch语句但是switch语句中的变量赋值通过了一个错误?

var answers, payload;
switch (action.type) {
  case ANSWER_FETCH_FAILED:
    return Object.assign({}, initialState, action.payload);
  case REMOVE_ANSWERS:
    // condition for removing the user answers  from answers

    /*line 42 */
    answers = Object.assign([], initialState.answers),

    payload = Object.assign({}, action.payload);
    // removing the deleted answer
    answers = answers.filter(ans => ans.authorId !== payload.authorId);
    // deleting the user id from payload
    delete payload.authorId;
    return Object.assign({}, initialState, { answers }, payload);
  case ANSWERED:
    /*line 50 */
    answers = Object.assign([], initialState.answers),

    payload = Object.assign({}, action.payload);
    return Object.assign({}, initialState, action.payload);
  default:
    return initialState;
}

这是反应中显示的错误

./双人床/reducers/post reducer.就是

第42行:预期赋值或函数调用,而是看到表达式no-unused-expressions

第50行:预期赋值或函数调用,而是看到表达式no-unused-expressions

javascript reactjs react-redux switch-statement
1个回答
0
投票

用分号,替换第42行和第50行末尾的逗号;

answers = Object.assign([], initialState.answers),

answers = Object.assign([], initialState.answers);
© www.soinside.com 2019 - 2024. All rights reserved.