20. Components
Building UI with Components
In standard HTML, you are limited to the built-in tags the browser gives you (<div>, <p>, <button>). React allows you to build your own custom tags. A Component is an independent, reusable piece of the user interface.
Function-Based Components
In modern React, components are simply JavaScript functions that return JSX. Historically, developers used "Class Components", but functional components are now the absolute industry standard.
Nesting and Reusability
The true power of components is that they can be nested inside one another. You can build a small component (like a <Button />), and use it multiple times inside a larger component (like a <Navbar />).
Separation of Concerns
By breaking your UI down into smaller components, your codebase becomes vastly easier to manage. If the subscription button breaks, you don't have to search through a massive 2,000-line HTML file; you just open the SubscribeButton.jsx file and fix it there.
Knowledge Check
Ready to test your understanding of 20. Components?