React-redux Spread operator in reducer returning error “unexpected token”

爱⌒轻易说出口 提交于 2019-12-03 15:35:04

It is about presets, actually.

Array spread is part of ES2015 standard and you use it here

        return [...state,
            {
             id:action.id,
             text: action.text,
             completed:false
            }
        ];

However, here

        return {
          ...todo, //returning error
          completed: !todo.completed
        };

you use object spread which is not part of the standard, but a stage 2 proposal.

You need to enable support of this proposal in Babel: https://babeljs.io/docs/plugins/transform-object-rest-spread/ or desugar it into Object.assign calls (see this part of the proposal)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!