Using ES6 / ES2015 spread operator – but also removing excess params

Building some custom enhancements to existing components, I wanted to use the ES6 style spread props to automatically pass any params through to the underlying base component. However, it was giving me console log errors for “unknown props“. Since this was a React Bootstrap component, I didn’t want to touch the core component.

To clone the props, but get rid of my enhanced props, I used an assign & delete to clone the original object and then remove the excess parts.

const objPassthrough = Object.assign({}, this.props)

delete objPassthrough.notUsed1
delete objPassthrough.notUsed2
delete objPassthrough.notUsed3

This gives a clean object without the “notUsed” params, and made bootstrap happy again.