代码之家  ›  专栏  ›  技术社区  ›  Riantori

在redux get上对函数参数“state”的赋值未能编译[重复]

  •  0
  • Riantori  · 技术社区  · 8 年前

    我刚刚学习了redux,在我的reducer代码中出现了这个错误,他们说“赋值给函数参数‘state’”,并使我的代码中断,已经按照eslint的建议,但似乎仍然不起作用,下面是我的代码

    const fooReducer = (state = {}, action) => {
      switch (action.type) {
       case 'INC': {
        state = {
         ...state,
         foo: action.payload,
       };
       break;
     }
     case 'DEC': {
       state = {
       ...state,
       lorem: action.payload,
       };
       break;
      }
    }
    return state;
    };
    

    error message 非常感谢你的帮助。

    1 回复  |  直到 8 年前
        1
  •  1
  •   Jacob    8 年前

    排列运算符( ... )在生成过程中未被识别。你会想要添加 the appropriate Babel transform 以便webpack识别并传输该代码。把这样的东西合并到你的 .babelrc 在完成插件的dev安装后:

    {
      "plugins": ["transform-object-rest-spread"]
    }