React - props.children
Composition and props.children
<section id="composition" class="chapter">
<div>
<h1>Composition and <br>props.children</h1>
</div>
</section>
<section><h1>Composition vs. inheritance</h1>
<div class="row">
<div class="col-6">
<p>
You know the concept of
<span class="is-text-bold">inheritance</span> from object-oriented programming. It means that a class can extend another class with new functionalities.
</p>
<p>While this is a good programming paradigm, it does not apply to React.</p>
</div>
<div class="col-6">
<p>
Beginner React programmers sometimes want to create components using inheritance (after all, we use classes).
</p>
<p>
For example, it may seem that
<span class="is-text-bold">a yes/no message</span> and an
<span class="is-text-bold">informational message</span> can and should inherit from a
<span class="is-text-bold">common, generic message component</span>.
</p>
<p>
This is not the case, however –
<span class="is-text-bold">in React, composition is always preferred</span>.
</p>
</div>
</div>
</section>Composition
Composition - slide 2
Last updated