React interview cheatsheet series
React has a powerful composition model, and the React Team recommends to use composition instead of inheritance to reuse code between components. However, there can be cases where inheritance is preferred to composition like reusing a particular functionality of a component than the component itself.
As you know, in OOP inheritance emans that classes and objects inherit properties and behaviors from their parent.
Many times, a parent component doesn't know about its children, think in a sidebar or an alert box component, so we can use composition as a powerful tool to reuse code and share props between components.
Composition uses the children prop to pass the all the elements, see:
Also, using composition is a simple way to avoid props drilling when we have just a few nesting components.