Reputation: 71
I was wondering can a child component have multiple parent components and if this should be done? so for example
<parent1 /> ------> <theChild />
<parent2 /> ------>
both call theChild component separately. Any advice would be much appreciated. Thank you
Upvotes: 2
Views: 1713
Reputation: 20634
All children in React can only have one parent. Think of a div
. Everything inside the div
are its children or grandchildren, but the things inside that div
cannot be inside a different div
, they are inside that one.
However the same function or class that the component is created from can be called / instantiated and rendered by different parents creating different children of the same type, each with their own unique state, variables and functions or methods.
Upvotes: 2