复制反应组件属性时,Spread语法会出错

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

我正在使用react,我正在尝试使用spread语法。由于某种原因它不起作用,它给出了一个错误:

const { className, children, ...otherprops } = this.props;

知道我做错了什么吗?

javascript reactjs spread-syntax
1个回答
4
投票

你得到Unexpected token因为你缺少一个babel预设,stage-0

With stage-0, it works

Without stage-0, it doesn't work

为了添加它,你必须

1º安装它

npm install --save-dev babel-preset-stage-0

2º将它添加到.babelrc

{
  "presets": ["react","es2015","stage-0"]
}
© www.soinside.com 2019 - 2024. All rights reserved.