What is the difference between Higher Order Component (HOC) and Inheritance in React native component









up vote
2
down vote

favorite












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 .?










share|improve this question



















  • 2




    HOCs use composition, reactjs.org/docs/composition-vs-inheritance.html . The point of this is similar to OOP's en.wikipedia.org/wiki/Composition_over_inheritance . Which is the best way to achieve the Parent-> Child -> GrandChild hierarchical relationship - there is no 'best way' because this depends on components. If you have specific case in mind, consider reasking the question with specific code example.
    – estus
    Nov 9 at 7:18










  • Sure will modify the Question with sample code snippet.
    – Gowthaman
    Nov 9 at 7:31










  • Do you have an example that would be more real-world? this.state inheritance in child components won't work well with component composition but I cannot think of a good reason to ever do that. If the state becomes that complex, there is possibly a need to use state management (Redux?). Components need to be refactored to fit composition better but I cannot suggest how to do that because it's unclear what components really do. Btw, onUpdate doesn't play well with inheritance because it's instance method and there will be no super.onUpdate, it should be prototype method.
    – estus
    Nov 9 at 9:34











  • Inheritance in JavaScript is prototypal. HOCs are composed functions.
    – evolutionxbox
    Nov 9 at 13:09














up vote
2
down vote

favorite












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 .?










share|improve this question



















  • 2




    HOCs use composition, reactjs.org/docs/composition-vs-inheritance.html . The point of this is similar to OOP's en.wikipedia.org/wiki/Composition_over_inheritance . Which is the best way to achieve the Parent-> Child -> GrandChild hierarchical relationship - there is no 'best way' because this depends on components. If you have specific case in mind, consider reasking the question with specific code example.
    – estus
    Nov 9 at 7:18










  • Sure will modify the Question with sample code snippet.
    – Gowthaman
    Nov 9 at 7:31










  • Do you have an example that would be more real-world? this.state inheritance in child components won't work well with component composition but I cannot think of a good reason to ever do that. If the state becomes that complex, there is possibly a need to use state management (Redux?). Components need to be refactored to fit composition better but I cannot suggest how to do that because it's unclear what components really do. Btw, onUpdate doesn't play well with inheritance because it's instance method and there will be no super.onUpdate, it should be prototype method.
    – estus
    Nov 9 at 9:34











  • Inheritance in JavaScript is prototypal. HOCs are composed functions.
    – evolutionxbox
    Nov 9 at 13:09












up vote
2
down vote

favorite









up vote
2
down vote

favorite











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 .?










share|improve this question















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 .?






class Parent extends Component

constructor(props)

super(props);
this.state =
value: "Parent",
BaseText: "Inheritance Example"



onUpdate = () =>
console.log("Update called at Parent")






class Parent extends Component

constructor(props)

super(props);
this.state =
value: "Parent",
BaseText: "Inheritance Example"



onUpdate = () =>
console.log("Update called at Parent")






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>
)






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>
)






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>
)






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>
)







reactjs react-native ecmascript-6 es6-class






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 9 at 8:21

























asked Nov 9 at 7:04









Gowthaman

218314




218314







  • 2




    HOCs use composition, reactjs.org/docs/composition-vs-inheritance.html . The point of this is similar to OOP's en.wikipedia.org/wiki/Composition_over_inheritance . Which is the best way to achieve the Parent-> Child -> GrandChild hierarchical relationship - there is no 'best way' because this depends on components. If you have specific case in mind, consider reasking the question with specific code example.
    – estus
    Nov 9 at 7:18










  • Sure will modify the Question with sample code snippet.
    – Gowthaman
    Nov 9 at 7:31










  • Do you have an example that would be more real-world? this.state inheritance in child components won't work well with component composition but I cannot think of a good reason to ever do that. If the state becomes that complex, there is possibly a need to use state management (Redux?). Components need to be refactored to fit composition better but I cannot suggest how to do that because it's unclear what components really do. Btw, onUpdate doesn't play well with inheritance because it's instance method and there will be no super.onUpdate, it should be prototype method.
    – estus
    Nov 9 at 9:34











  • Inheritance in JavaScript is prototypal. HOCs are composed functions.
    – evolutionxbox
    Nov 9 at 13:09












  • 2




    HOCs use composition, reactjs.org/docs/composition-vs-inheritance.html . The point of this is similar to OOP's en.wikipedia.org/wiki/Composition_over_inheritance . Which is the best way to achieve the Parent-> Child -> GrandChild hierarchical relationship - there is no 'best way' because this depends on components. If you have specific case in mind, consider reasking the question with specific code example.
    – estus
    Nov 9 at 7:18










  • Sure will modify the Question with sample code snippet.
    – Gowthaman
    Nov 9 at 7:31










  • Do you have an example that would be more real-world? this.state inheritance in child components won't work well with component composition but I cannot think of a good reason to ever do that. If the state becomes that complex, there is possibly a need to use state management (Redux?). Components need to be refactored to fit composition better but I cannot suggest how to do that because it's unclear what components really do. Btw, onUpdate doesn't play well with inheritance because it's instance method and there will be no super.onUpdate, it should be prototype method.
    – estus
    Nov 9 at 9:34











  • Inheritance in JavaScript is prototypal. HOCs are composed functions.
    – evolutionxbox
    Nov 9 at 13:09







2




2




HOCs use composition, reactjs.org/docs/composition-vs-inheritance.html . The point of this is similar to OOP's en.wikipedia.org/wiki/Composition_over_inheritance . Which is the best way to achieve the Parent-> Child -> GrandChild hierarchical relationship - there is no 'best way' because this depends on components. If you have specific case in mind, consider reasking the question with specific code example.
– estus
Nov 9 at 7:18




HOCs use composition, reactjs.org/docs/composition-vs-inheritance.html . The point of this is similar to OOP's en.wikipedia.org/wiki/Composition_over_inheritance . Which is the best way to achieve the Parent-> Child -> GrandChild hierarchical relationship - there is no 'best way' because this depends on components. If you have specific case in mind, consider reasking the question with specific code example.
– estus
Nov 9 at 7:18












Sure will modify the Question with sample code snippet.
– Gowthaman
Nov 9 at 7:31




Sure will modify the Question with sample code snippet.
– Gowthaman
Nov 9 at 7:31












Do you have an example that would be more real-world? this.state inheritance in child components won't work well with component composition but I cannot think of a good reason to ever do that. If the state becomes that complex, there is possibly a need to use state management (Redux?). Components need to be refactored to fit composition better but I cannot suggest how to do that because it's unclear what components really do. Btw, onUpdate doesn't play well with inheritance because it's instance method and there will be no super.onUpdate, it should be prototype method.
– estus
Nov 9 at 9:34





Do you have an example that would be more real-world? this.state inheritance in child components won't work well with component composition but I cannot think of a good reason to ever do that. If the state becomes that complex, there is possibly a need to use state management (Redux?). Components need to be refactored to fit composition better but I cannot suggest how to do that because it's unclear what components really do. Btw, onUpdate doesn't play well with inheritance because it's instance method and there will be no super.onUpdate, it should be prototype method.
– estus
Nov 9 at 9:34













Inheritance in JavaScript is prototypal. HOCs are composed functions.
– evolutionxbox
Nov 9 at 13:09




Inheritance in JavaScript is prototypal. HOCs are composed functions.
– evolutionxbox
Nov 9 at 13:09












1 Answer
1






active

oldest

votes

















up vote
0
down vote













React promotes composition as an alternative to class inheritance. Components were designed to be efficiently composed. Hooks API augments function components with features that previously required class components to be used.



This doesn't mean that inheritance isn't allowed. The problem with it is that existing patterns such as higher-order component are widely used in React ecosystem and aren't compatible with OOP:



const withBaz = Comp => <Comp baz />

@withBaz
class Bar extends Foo ...


This approach is common but it isn't OOP friendly because in this case Bar is actually not a class anymore but arrow function, it cannot be inherited further.



There are no problems with using OOP for first-party React components as long as a developer controls all components in class hierarchy, but this may be unpractical because there always may be a need to involve third-party code that isn't OOP-friendly. The use of composition where it fits results in more flexible design.






share|improve this answer




















  • with composition is it possible to have lifecycle events.? say Parent class has a ComponentDidMount(), rendering Child should call the Componentdidmount of its own and also the lifecycle event of Parent also .?
    – Gowthaman
    Nov 9 at 10:28










  • componentDidMount will be called in both components if they were mounted (i.e. successfully rendered).
    – estus
    Nov 9 at 10:29










  • One last question. How can i achieve inheritence of state property in Child to use both the Parent and its own state property .?
    – Gowthaman
    Nov 9 at 12:51










  • You probably don't need. That's why I asked for real-world example. It could be expressed in a way that is idiomatic to React without inheritance. Usually you need to use inheritance only when you need to extend the functionality of third-party class components you cannot modify directly.
    – estus
    Nov 9 at 12:56










  • Say for example, We are building a DataEntry Form(include Input controls, Grids etc..) and the List Form(Includes search control and a Grid) there some common methods like exporting the grid to Excel, Fetching the Records for that grid, state properties such as FormName, GridName. So i want those common methods and state properties to be part of the AbstractForm.js this will act as the parent for both DataentryForm.js(the details about input fields are specific to this child) and ListForm.js(details about the search field is specific to this child).
    – Gowthaman
    Nov 9 at 13:11










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53221196%2fwhat-is-the-difference-between-higher-order-component-hoc-and-inheritance-in-r%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













React promotes composition as an alternative to class inheritance. Components were designed to be efficiently composed. Hooks API augments function components with features that previously required class components to be used.



This doesn't mean that inheritance isn't allowed. The problem with it is that existing patterns such as higher-order component are widely used in React ecosystem and aren't compatible with OOP:



const withBaz = Comp => <Comp baz />

@withBaz
class Bar extends Foo ...


This approach is common but it isn't OOP friendly because in this case Bar is actually not a class anymore but arrow function, it cannot be inherited further.



There are no problems with using OOP for first-party React components as long as a developer controls all components in class hierarchy, but this may be unpractical because there always may be a need to involve third-party code that isn't OOP-friendly. The use of composition where it fits results in more flexible design.






share|improve this answer




















  • with composition is it possible to have lifecycle events.? say Parent class has a ComponentDidMount(), rendering Child should call the Componentdidmount of its own and also the lifecycle event of Parent also .?
    – Gowthaman
    Nov 9 at 10:28










  • componentDidMount will be called in both components if they were mounted (i.e. successfully rendered).
    – estus
    Nov 9 at 10:29










  • One last question. How can i achieve inheritence of state property in Child to use both the Parent and its own state property .?
    – Gowthaman
    Nov 9 at 12:51










  • You probably don't need. That's why I asked for real-world example. It could be expressed in a way that is idiomatic to React without inheritance. Usually you need to use inheritance only when you need to extend the functionality of third-party class components you cannot modify directly.
    – estus
    Nov 9 at 12:56










  • Say for example, We are building a DataEntry Form(include Input controls, Grids etc..) and the List Form(Includes search control and a Grid) there some common methods like exporting the grid to Excel, Fetching the Records for that grid, state properties such as FormName, GridName. So i want those common methods and state properties to be part of the AbstractForm.js this will act as the parent for both DataentryForm.js(the details about input fields are specific to this child) and ListForm.js(details about the search field is specific to this child).
    – Gowthaman
    Nov 9 at 13:11














up vote
0
down vote













React promotes composition as an alternative to class inheritance. Components were designed to be efficiently composed. Hooks API augments function components with features that previously required class components to be used.



This doesn't mean that inheritance isn't allowed. The problem with it is that existing patterns such as higher-order component are widely used in React ecosystem and aren't compatible with OOP:



const withBaz = Comp => <Comp baz />

@withBaz
class Bar extends Foo ...


This approach is common but it isn't OOP friendly because in this case Bar is actually not a class anymore but arrow function, it cannot be inherited further.



There are no problems with using OOP for first-party React components as long as a developer controls all components in class hierarchy, but this may be unpractical because there always may be a need to involve third-party code that isn't OOP-friendly. The use of composition where it fits results in more flexible design.






share|improve this answer




















  • with composition is it possible to have lifecycle events.? say Parent class has a ComponentDidMount(), rendering Child should call the Componentdidmount of its own and also the lifecycle event of Parent also .?
    – Gowthaman
    Nov 9 at 10:28










  • componentDidMount will be called in both components if they were mounted (i.e. successfully rendered).
    – estus
    Nov 9 at 10:29










  • One last question. How can i achieve inheritence of state property in Child to use both the Parent and its own state property .?
    – Gowthaman
    Nov 9 at 12:51










  • You probably don't need. That's why I asked for real-world example. It could be expressed in a way that is idiomatic to React without inheritance. Usually you need to use inheritance only when you need to extend the functionality of third-party class components you cannot modify directly.
    – estus
    Nov 9 at 12:56










  • Say for example, We are building a DataEntry Form(include Input controls, Grids etc..) and the List Form(Includes search control and a Grid) there some common methods like exporting the grid to Excel, Fetching the Records for that grid, state properties such as FormName, GridName. So i want those common methods and state properties to be part of the AbstractForm.js this will act as the parent for both DataentryForm.js(the details about input fields are specific to this child) and ListForm.js(details about the search field is specific to this child).
    – Gowthaman
    Nov 9 at 13:11












up vote
0
down vote










up vote
0
down vote









React promotes composition as an alternative to class inheritance. Components were designed to be efficiently composed. Hooks API augments function components with features that previously required class components to be used.



This doesn't mean that inheritance isn't allowed. The problem with it is that existing patterns such as higher-order component are widely used in React ecosystem and aren't compatible with OOP:



const withBaz = Comp => <Comp baz />

@withBaz
class Bar extends Foo ...


This approach is common but it isn't OOP friendly because in this case Bar is actually not a class anymore but arrow function, it cannot be inherited further.



There are no problems with using OOP for first-party React components as long as a developer controls all components in class hierarchy, but this may be unpractical because there always may be a need to involve third-party code that isn't OOP-friendly. The use of composition where it fits results in more flexible design.






share|improve this answer












React promotes composition as an alternative to class inheritance. Components were designed to be efficiently composed. Hooks API augments function components with features that previously required class components to be used.



This doesn't mean that inheritance isn't allowed. The problem with it is that existing patterns such as higher-order component are widely used in React ecosystem and aren't compatible with OOP:



const withBaz = Comp => <Comp baz />

@withBaz
class Bar extends Foo ...


This approach is common but it isn't OOP friendly because in this case Bar is actually not a class anymore but arrow function, it cannot be inherited further.



There are no problems with using OOP for first-party React components as long as a developer controls all components in class hierarchy, but this may be unpractical because there always may be a need to involve third-party code that isn't OOP-friendly. The use of composition where it fits results in more flexible design.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 9 at 9:30









estus

64.6k2195203




64.6k2195203











  • with composition is it possible to have lifecycle events.? say Parent class has a ComponentDidMount(), rendering Child should call the Componentdidmount of its own and also the lifecycle event of Parent also .?
    – Gowthaman
    Nov 9 at 10:28










  • componentDidMount will be called in both components if they were mounted (i.e. successfully rendered).
    – estus
    Nov 9 at 10:29










  • One last question. How can i achieve inheritence of state property in Child to use both the Parent and its own state property .?
    – Gowthaman
    Nov 9 at 12:51










  • You probably don't need. That's why I asked for real-world example. It could be expressed in a way that is idiomatic to React without inheritance. Usually you need to use inheritance only when you need to extend the functionality of third-party class components you cannot modify directly.
    – estus
    Nov 9 at 12:56










  • Say for example, We are building a DataEntry Form(include Input controls, Grids etc..) and the List Form(Includes search control and a Grid) there some common methods like exporting the grid to Excel, Fetching the Records for that grid, state properties such as FormName, GridName. So i want those common methods and state properties to be part of the AbstractForm.js this will act as the parent for both DataentryForm.js(the details about input fields are specific to this child) and ListForm.js(details about the search field is specific to this child).
    – Gowthaman
    Nov 9 at 13:11
















  • with composition is it possible to have lifecycle events.? say Parent class has a ComponentDidMount(), rendering Child should call the Componentdidmount of its own and also the lifecycle event of Parent also .?
    – Gowthaman
    Nov 9 at 10:28










  • componentDidMount will be called in both components if they were mounted (i.e. successfully rendered).
    – estus
    Nov 9 at 10:29










  • One last question. How can i achieve inheritence of state property in Child to use both the Parent and its own state property .?
    – Gowthaman
    Nov 9 at 12:51










  • You probably don't need. That's why I asked for real-world example. It could be expressed in a way that is idiomatic to React without inheritance. Usually you need to use inheritance only when you need to extend the functionality of third-party class components you cannot modify directly.
    – estus
    Nov 9 at 12:56










  • Say for example, We are building a DataEntry Form(include Input controls, Grids etc..) and the List Form(Includes search control and a Grid) there some common methods like exporting the grid to Excel, Fetching the Records for that grid, state properties such as FormName, GridName. So i want those common methods and state properties to be part of the AbstractForm.js this will act as the parent for both DataentryForm.js(the details about input fields are specific to this child) and ListForm.js(details about the search field is specific to this child).
    – Gowthaman
    Nov 9 at 13:11















with composition is it possible to have lifecycle events.? say Parent class has a ComponentDidMount(), rendering Child should call the Componentdidmount of its own and also the lifecycle event of Parent also .?
– Gowthaman
Nov 9 at 10:28




with composition is it possible to have lifecycle events.? say Parent class has a ComponentDidMount(), rendering Child should call the Componentdidmount of its own and also the lifecycle event of Parent also .?
– Gowthaman
Nov 9 at 10:28












componentDidMount will be called in both components if they were mounted (i.e. successfully rendered).
– estus
Nov 9 at 10:29




componentDidMount will be called in both components if they were mounted (i.e. successfully rendered).
– estus
Nov 9 at 10:29












One last question. How can i achieve inheritence of state property in Child to use both the Parent and its own state property .?
– Gowthaman
Nov 9 at 12:51




One last question. How can i achieve inheritence of state property in Child to use both the Parent and its own state property .?
– Gowthaman
Nov 9 at 12:51












You probably don't need. That's why I asked for real-world example. It could be expressed in a way that is idiomatic to React without inheritance. Usually you need to use inheritance only when you need to extend the functionality of third-party class components you cannot modify directly.
– estus
Nov 9 at 12:56




You probably don't need. That's why I asked for real-world example. It could be expressed in a way that is idiomatic to React without inheritance. Usually you need to use inheritance only when you need to extend the functionality of third-party class components you cannot modify directly.
– estus
Nov 9 at 12:56












Say for example, We are building a DataEntry Form(include Input controls, Grids etc..) and the List Form(Includes search control and a Grid) there some common methods like exporting the grid to Excel, Fetching the Records for that grid, state properties such as FormName, GridName. So i want those common methods and state properties to be part of the AbstractForm.js this will act as the parent for both DataentryForm.js(the details about input fields are specific to this child) and ListForm.js(details about the search field is specific to this child).
– Gowthaman
Nov 9 at 13:11




Say for example, We are building a DataEntry Form(include Input controls, Grids etc..) and the List Form(Includes search control and a Grid) there some common methods like exporting the grid to Excel, Fetching the Records for that grid, state properties such as FormName, GridName. So i want those common methods and state properties to be part of the AbstractForm.js this will act as the parent for both DataentryForm.js(the details about input fields are specific to this child) and ListForm.js(details about the search field is specific to this child).
– Gowthaman
Nov 9 at 13:11

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53221196%2fwhat-is-the-difference-between-higher-order-component-hoc-and-inheritance-in-r%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)