I am trying to create some kind of class composition in react:
class Entity {
constructor(props) {
super(props);
}
renderPartial() {
return (<div>Entity</div>)
}
render() {
return (<div>header {this.renderPartial()}</div>);
}
}
class Person extends Entity{
constructor(props) {
super(props);
}
renderPartial() {
return (<div>Person</div>)
}
}
class Manager extends Person {
constructor(props) {
super(props);
}
renderPartial() {
return (<div>Manager</div>)
}
}
In the following example Person
extends from Entity
class. And the goal here is to render partial content inside of the extended class. So for the simplicity sake I just render class name. This way everything works fine with Person class and it renders its text. But when I extend Manager from Person it writes <div>Person</div>
and I can't understand why. Is there any way to override renderPartial
inside of the Manager
class?