Can I use destructuring somehow inside an if statement?
问题 is there a way I could do something like this ? if({color, size, shape} = this.props){ console.log('Received all props!'); } else { console.log('There are some missing props'); } I want to know if I received all needed data through my Component's props, and if not then throw an error. It's for creating reusable components. 回答1: You could use default values: function missing(prop) { throw new TypeError(`there is a missing ${prop} property`); } … try { const { color = missing("color"), size =