I am new to react native from .net background,
Here the Question is how HOC is different from inheritance in OOPS concept by having a parent class with base properties and child that extends the Base and use the state, properties and base methods from the Base class.
Which is the best way to achieve the Parent-> Child -> GrandChild hierarchical relationship in React Components .?
For Example:
Parent.js Looks like
class Parent extends Component
{
constructor(props)
{
super(props);
this.state = {
value: "Parent",
BaseText: "Inheritance Example"
}
}
onUpdate = () => {
console.log("Update called at Parent")
}
}
Child.js which extends Parent.js
class Child extends Parent
{
constructor(props)
{
super(props);
//this state should inherit the properties of Parent and override only the value property
this.state = {
value: "Child",
}
}
onUpdate = () => {
super.onUpdate();
console.log("Update called at Child view")
}
render()
{
return(
<View>
<Text> Child View</Text>
</View>
)
}
}
The GrandChild.js extends from Child.js
class GrandChild extends Child
{
constructor(props)
{
super(props);
//this state should inherit the properties of Child, Parent and properties specific to this
this.state = {
value: "GrandChild",
Name: "Test Grand Child"
}
}
onUpdate = () => {
super.onUpdate();
console.log("Update called at Grand Child view")
}
render()
{
return(
<View>
<Text> Grand Child View</Text>
</View>
)
}
}
Is this the right way of implementing abstraction in react native say Parent class will have the common state properties and the child inherits the Parent state and has its own properties.
How to inherit state and how to update values to state in this case .?