首先,我来了PHP的背景,我目前有点构建中间件反应,我会做这个会是这样的方式:矩形扩展中间件
class Middleware extends React.Component {
funcOne(data) {
return data;
}
funcTwo(data) {
return (
<div>
{ data }
<br />
{ this.funcThree('Third function') }
</div>
);
}
}
class MyComponent extends Middleware {
funcOne(data) {
return `Rewrite of ${data}`;
}
funcThree(data) {
return data;
}
render() {
return (
<div>
{ this.funcOne('First function') }
{ this.funcTwo('Second function') }
</div>
);
}
}
class MySecondComponent extends Middleware {
funcThree(data) {
return data;
}
render() {
return (
<div>
{ this.funcOne('First function') }
{ this.funcTwo('Second function') }
</div>
);
}
}
ReactDOM.render(
<div>
<MyComponent />
<hr />
<MySecondComponent />
</div>,
document.getElementById('root'),
);
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.js"></script>
<div id="root"></div>
但是我真的找不到有关是否做这件事的任何文件。 那么,这是错的? 如果是这样,我应该怎么做呢?
嗨,我确实简化了一些组件,但是我会在组件中使用组件函数,例如'componentWillUnmount'aso,我也会喜欢在其他组件中使用“上”组件 – Touchpad
我肯定会再次回答这个问题 - 我想在所有的时间里,我一直在使用React,我从来没有*必须继承一个组件(并且如链接到文档,他们积极建议不要这样做)。 –
有问题的组件将在整个项目中广泛使用,我真的不知道Hoc如何让你按照我的意愿来回发送功能 – Touchpad