flâneur — a map of the web's best reading

Composition vs Inheritance – React

reactjs.org · 874 words · saved by 1 readers

A JavaScript library for building user interfaces

These docs are old and won’t be updated. Go to react.dev for the new React docs. React has a powerful composition model, and we recommend using composition instead of inheritance to reuse code between components. In this section, we will consider a few problems where developers new to React often reach for inheritance, and show how we can solve them with composition. Containment Some components don’t know their children ahead of time. This is especially common for components like Sidebar or Dialog that represent generic “boxes”. We recommend that such components use the special children prop t

Explore this link on the map →

saved by

related reading