React favours composition over inheritance

In this lesson, we study why React programmers prefer to use class composition over class inheritance.

Why not inheritance?

Imagine you are making a video game and need two characters: one that can shoot lasers and another that can cast spells. Both characters have a name and health.

You solve this problem neatly with inheritance. As per the following, a class structure with one parent class, the character, and two child classes called caster and shooter can be created.

Get hands-on with 1400+ tech skills courses.