Composition là kỹ thuật xây dựng component phức tạp từ các component đơn giản hơn thay vì kế thừa.
- React khuyến khích composition vì nó linh hoạt hơn, dễ test hơn và tránh các vấn đề của prototype chain.
- Patterns như children prop, render props, và slots đều là biểu hiện của composition.
Composition is the technique of building complex components from simpler ones rather than using inheritance.
- React favors composition because it is more flexible, easier to test, and avoids the pitfalls of prototype chains.
- Patterns like the children prop, render props, and slots are all expressions of composition.