Component-Based Architecture

Beginner · 30 min

Why UIs get built from small, reusable pieces with their own state and inputs — a framework-agnostic idea shown here through React.

Before thisChoosing a Frontend Framework

Web Dev Simplified · 30 min

Component-Based Architecture

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by Web Dev SimplifiedReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • A component is a self-contained, reusable piece of UI that owns its own markup, behavior, and optionally its own state, so a page is built by composing many small components instead of one large template.
  • Props (also called inputs or attributes depending on the framework) are how a parent passes data down into a component — they make a component configurable and reusable in different contexts.
  • State is data a component manages internally and can change over time; when state changes, the component re-renders to reflect the new value.
  • Composition means building complex UI by nesting and combining simple components rather than writing one component that tries to do everything.
  • Every major framework — React, Vue, Angular, Svelte — implements this same component model under different names and syntax, which is why the mental model transfers even when the code doesn't.

Before components: one big template

Imagine building a page as a single HTML file with a pile of JavaScript sprinkled in. A product listing page has a header, a search bar, a grid of product cards, a pagination control, and a footer — all defined in one place, all reading and writing the same tangle of global variables. Change how a product card looks, and you have to find every spot in that one file that happens to render a card, because there’s no single definition of “product card” to change. Reuse it on a different page, and you’re copy-pasting markup and hoping you copied the right version.

The component model is the fix: instead of one template, you define each distinct piece of UI exactly once — as a component — with its own markup, behavior, and (optionally) its own data, and then you build pages by assembling those pieces together. A “product card” becomes a single definition you can place anywhere, configure differently each time, and update in exactly one place when its design changes everywhere it’s used.

This lesson teaches the model using React, because the linked video does, but don’t mistake that for “this is a React idea.” Vue calls its unit a component too and its props largely work the same way. Angular calls the same concept a component as well, with @Input() decorators standing in for props. Svelte uses the word component and passes data in through attributes on the tag. The names and syntax differ; the shape of the idea — self-contained, reusable, composable units of UI — doesn’t.

Props: making a component configurable

A component that can only ever render exactly one thing isn’t very reusable. A Button component that always says “Submit” is only useful on one form. Props solve this: they’re the inputs a parent passes into a component when it uses it, similar to arguments passed into a function.

<Button label="Submit" onClick={handleSubmit} />
<Button label="Cancel" onClick={handleCancel} />

Here, label and onClick are props — the same Button component renders different text and runs different code depending on what it’s handed. The component itself doesn’t know or care what specific label it’ll get; it just knows how to render whatever label it’s given. This is exactly why a single Button definition can be reused across an entire application instead of being hand-copied with small tweaks every time it’s needed.

The naming differs by framework — React calls them props, Angular calls them inputs, Vue calls them props too but declares them a little differently, Svelte calls them exported props — but the role is identical in every case: data flowing in from whoever is using the component.

State: what a component remembers about itself

Props come from outside. State is different — it’s data a component owns and manages itself, and it can change over time in response to user interaction. A checkbox needs to remember whether it’s checked. A dropdown needs to remember whether it’s open. A form input needs to remember what’s currently typed into it. None of that comes from a parent; the component tracks it internally.

The important behavior of state is that when it changes, the component re-renders — the framework re-evaluates what the UI should look like given the new state and updates the DOM accordingly. This is the same view = f(state) idea from the framework landscape as a whole, just scoped down to one component instead of the whole page. Click a “like” button, the component’s internal liked state flips from false to true, and the component redraws itself with the new value — without you manually finding and updating the heart icon’s class by hand.

Every framework has its own flavor of this: React has useState, Vue has ref and reactive, Angular has component class properties combined with its change detection, Svelte has reactive let declarations with its compiler wiring up the updates. Different machinery, same job: letting a component hold data that changes and reflecting that change on screen automatically.

Composition: building up, not out

Once you have components that take props and manage their own state, the natural next move is to nest them inside each other. A ProductPage component doesn’t render raw HTML for a product grid — it renders a ProductGrid component, which in turn renders several ProductCard components, each one configured with different props. A ProductCard might itself contain a Price component and an AddToCartButton component.

This is composition: instead of one component trying to handle search, filtering, display, and checkout all in one file, you break the problem into small components, each responsible for one thing, and combine them by nesting. It’s the same reason good backend code gets split into small functions instead of one giant one — smaller, focused pieces are easier to test, easier to reuse, and easier to reason about in isolation.

Composition is also where frameworks tend to differ in approach the most visibly — React’s “children” prop, Vue’s “slots,” and Angular’s “content projection” are all different mechanisms for the same underlying need: letting a parent component decide what gets rendered inside a child component, rather than hard-coding it. The linked deeper-dive video is worth watching specifically because it walks through composition in React, Angular, and Vue side by side, which makes it obvious how much of this is the same idea wearing different clothes.

Why this is the foundation for everything else in this group

Routing, rendering strategies, state management at the app level — all of it assumes you already have a way to break a UI into independently testable, reusable chunks. Once you can look at any framework’s docs and recognize “oh, this is just their version of props” or “this is just their version of local state,” the framework-specific syntax stops being the hard part. The hard part — structuring an interface as composed, self-contained pieces — is the part that actually transfers.

Check yourself

  1. 01What is a component, in the framework-agnostic sense?

    A self-contained, reusable unit of UI that bundles its own markup, behavior, and often its own local state, which can be composed with other components to build a page.

  2. 02What's the difference between props and state?

    Props are data passed into a component from the outside, by a parent, and the component doesn't change them itself; state is data a component owns and manages internally, which it can update over time.

  3. 03Why does "composition" matter as a design principle rather than just a technical detail?

    It keeps each component small and focused on one job, so complex UI is built by combining simple, well-understood pieces instead of growing one component until it's unmanageable.

  4. 04Is the component model specific to React?

    No — Vue, Angular, and Svelte all have their own version of components, props, and local state, just under different names and syntax; the underlying idea is shared across frameworks.

Go deeper

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark