Destructuring object and ignore one of the results

前端 未结 4 1534
挽巷
挽巷 2020-12-18 18:15

I have:

const section = cloneElement(this.props.children, {
  className: this.props.styles.section,
  ...this.props,
});

Inside this.

4条回答
  •  执笔经年
    2020-12-18 18:40

    I like ctrlplusb's answer, but here is an alternative using Object.assign if you don't want to add a new babel preset:

    const section = cloneElement(this.props.children, {
        className: this.props.styles.section,
        ...Object.assign({}, this.props, {
            styles: undefined
        })
    });
    

提交回复
热议问题