Facebook Pixel

Why does React prefer composition over inheritance?

Because composition scales better. Instead of extending base components and creating rigid hierarchies, you build small focused components and combine them. This is more flexible and easier to change as the app grows.

Verify This Answer

Cross-check this information using these trusted sources:

More FAQs in React Component Composition Best Practices for Clean Code

The children prop lets you pass nested elements into a component. A Card component that renders its children is reusable for any content, instead of being hardcoded to specific elements.

There is no fixed number, but a component with around fifteen props is usually doing too much. If you are passing many props, consider splitting the component or grouping related props into an object.

When two or more components need the same state, lift it to their common parent. But do not lift everything to the top of the tree; lift only what is genuinely shared to keep components focused.

Still have questions?

Browse all our FAQs or reach out to our support team

Want to upskill yourself?

Our courses are taking a Coffee break, but your curiosity shouldn't. Stay engaged with namastedev linkedin, youtube, discord and other resources while you wait.

0
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.