The name FinalButton
in your example won't be known to react since that is just your local variable name, but we change the name of the resulting component to whatever you want. Here I use "Final" in front of whatever the original name was.
Also, we can copy / merge the prop types over to the new element.
function EnhanceButton(Component) {
class _EnhancedButton extends React.Component {
static displayName = 'Final' + (Component.displayName || Component.name || 'Component');
render() {
return (
<Component { ...this.props }>{this.props.children}</Component>
);
}
}
_EnhancedButton.propTypes = Component.propTypes;
return _EnhancedButton;
}
This gives: Warning: Failed propType: Required prop handleClick
was not specified in Button
. Check the render method of FinalButton
.
Fiddle: https://jsfiddle.net/luggage66/qawhfLqb/
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…