React/Components/Lesson 03
Component Basics
30 min·theory
This chapter
1/4
JavaScript
Component Basics
💡 Why Should You Learn This?
🎯
This is the most fundamental concept in React and the foundation of everything.
💼
You can break a large screen into smaller pieces and manage them individually.
⚡
Reuse the same UI in multiple places to speed up development.
🏢 실무에서는
In real-world projects, you create components like Header, Footer, Sidebar, and ProductCard and assemble them together. For example, once you build a product card component for an online store, you can reuse it across hundreds of product listings.
Components — Assembling UI Like LEGO Bricks
Real-World Analogy: LEGO Bricks
When building a house with LEGO, you assemble wall, window, and roof bricks.
React components work the same way — you assemble small UI pieces like Button, Card, and Header to build a complete screen.
Why Learn This?
- ▸Reusability: A Button you build once can be used in hundreds of places
- ▸Separation: Each component is independent → easier to maintain
- ▸Testing: Can be tested in small, isolated units
Component Rules
1. Names must start with an uppercase letter (Button ✅, button ❌)
2. Must return JSX
3. Must return a single root element (or a Fragment <> >)
Basic Functional Component
💡 💡 Component Design Tips
- ▸Keep it small: Ideally under 100 lines
- ▸Props typing: TypeScript interface is required
- ▸Default values: Leverage default parameters
- ▸Composition pattern: Sub-components like Card.Header
This concept is central to React component development. Understand React's declarative UI paradigm, and clearly distinguish between props and state. A component should behave like a pure function — given the same input (props), it always returns the same output (JSX).
⚛️ React Pattern — Component Basics
Learn how to apply component basics in React step by step, with code examples.
1
🧩
1. Defining a Component
A function is itself a component
function Greeting({ name }) {
return <h1>Hello, {name}!</h1>;
}
↓
2
📤
2. Passing Props
Unidirectional data flow from parent → child
<Greeting name="Hong Gil-dong" />
↓
3
🔁
3. Reuse
The same component, used multiple times with different props
<Greeting name="Alice" />
<Greeting name="Bob" />
↓
4
💡
4. Unidirectional Data Flow
For a child to update parent state, it receives a callback function via props
🧩 Component Composition
Edit the code directly and changes will be reflected automatically after 0.7 seconds. Runs instantly in the browser using React 18 + Babel.
🖥️ Result — rendered React component
✏️ React 코드 수정하기 (클릭해서 열기)
⚛️ React 18 + Babel Standalone — see the result first, then edit the code yourself.
Check Your Understanding
What is the naming rule for React components?
Read this first: JSX Syntax
Up next: Props