import React from "react";
function withProps(WrappedComponent, extraProps) {
console.log(WrappedComponent,extraProps);
return function (props) {
console.log("withProps", props);
return <WrappedComponent {...props} {...extraProps} />;
};
}
function MyComponent(props) {
console.log('MyComponent',props)
return <div>{props.color}</div>;
}
const MyComponentWithExtraProps = withProps(MyComponent, { size: "large" });
export default function App() {
return (
<div>
<MyComponentWithExtraProps color="blue" />
</div>
);
}
高阶函数、高阶组件的实际应用举例 · Issue #54 · findxc/blog · GitHub