This commit is contained in:
2024-03-12 13:35:08 +08:00
parent 8f35d85bd8
commit cbe3a009e7

39
src/pages/HocPage.js Normal file
View File

@@ -0,0 +1,39 @@
/**
* 高阶组件
*/
import React, {Component} from 'react';
// function Child(props) {
// return <div>Child</div>
// }
const foo = Cmp => props => {
return (
<div className="border">
<Cmp {...props}/>
</div>
)
};
// const Foo=foo(Child);
class HocPage extends Component {
render() {
return (
<div>
<h1>HocPage</h1>
<Child></Child>
</div>
);
}
}
@foo
class Child extends Component {
render() {
return (
<div>
<p>Child</p>
</div>
);
}
}
export default HocPage;