React.js is not just a library for building user interfaces—it is a component-driven UI architecture designed to make complex front-end applications predictable, scalable, and performant.
1. What Exactly Is React?
React is a JavaScript library for building declarative, component-based user interfaces.
At its core, React answers one question:
“Given some data (state), what should the UI look like?”
You describe what the UI should be, not how to manipulate the DOM step by step.
2. The Core Philosophy of React
React is built on four fundamental principles:
1. Declarative UI
You describe UI as a function of state.
UI = f(state)
When state changes, React automatically updates the UI.
2. Component-Based Architecture
The UI is broken into independent, reusable components.
Each component:
- Has its own logic
- Can manage its own state
- Can be reused and composed
3. Unidirectional Data Flow
Data flows one way:
- Parent → Child
- State → UI
This eliminates unpredictable behavior.
4. Virtual DOM & Efficient Rendering
React does not directly manipulate the browser DOM for every change.
Instead:
- It builds a Virtual DOM
- Compares changes
- Updates only what is necessary
3. React Architecture Overview
At a high level, React consists of:
Application
├── Components
│ ├── State
│ ├── Props
│ └── Hooks
├── Virtual DOM
├── Reconciliation
├── React Fiber
└── Renderer (React DOM, React Native)
Let’s break each part down.
4. Components: The Building Blocks
A React application is a tree of components.
Function Components (Modern Standard)
function Button({ label }) {
return <button>{label}</button>;
}
A component is simply:
- A JavaScript function
- That returns JSX
- Based on inputs (props and state)
5. JSX: Syntax, Not Magic
JSX is syntactic sugar for React.createElement.
<h1>Hello</h1>
Is transformed into:
React.createElement("h1", null, "Hello");
JSX:
- Is not HTML
- Is JavaScript
- Gets compiled before runtime
6. Props: Data Flow Between Components
Props are read-only inputs passed to components.
<User name="Alex" />
function User({ name }) {
return <p>{name}</p>;
}
Important rules:
- Props are immutable
- Children cannot modify parent data
- Enables predictable UI behavior
7. State: Data That Changes Over Time
State represents mutable data that affects rendering.
const [count, setCount] = useState(0);
When state changes:
- React schedules an update
- Component re-renders
- Virtual DOM is updated
- Changes are committed to the real DOM
8. Hooks: React’s Functional Power System
Hooks allow function components to:
- Hold state
- Run side effects
- Access lifecycle features
Core Hooks
| Hook | Purpose |
|---|---|
useState |
Local state |
useEffect |
Side effects |
useContext |
Global/shared state |
useRef |
Mutable values |
useMemo |
Performance optimization |
useCallback |
Function memoization |
useEffect Lifecycle Mapping
useEffect(() => {
// componentDidMount
return () => {
// componentWillUnmount
};
}, []);
React no longer has class lifecycles—effects replaced them.
9. Virtual DOM: How React Really Works
React maintains an in-memory tree (Virtual DOM).
When state changes:
- A new Virtual DOM tree is created
- React compares it with the old one (diffing)
- Only changed nodes are updated in the real DOM
This process is called Reconciliation.
10. Reconciliation Algorithm
React uses:
- Heuristics
- Keys for lists
- Component identity
items.map(item => (
<Item key={item.id} />
))
Keys help React:
- Track elements
- Avoid unnecessary re-renders
- Maintain state correctly
11. React Fiber: The Internal Engine
Fiber is React’s reconciliation engine.
It enables:
- Incremental rendering
- Priority updates
- Interruptible work
- Concurrent rendering
This is why React feels fast even for large applications.
12. Rendering Process Step by Step
- State change occurs
- React schedules update
- Fiber builds work units
- Virtual DOM comparison
- Minimal DOM updates
- Browser repaint
React separates:
- Render phase (pure)
- Commit phase (DOM mutation)
13. Controlled vs Uncontrolled Components
Controlled Input
<input value={text} onChange={e => setText(e.target.value)} />
State controls the UI.
Uncontrolled Input
<input ref={inputRef} />
DOM controls the state.
React encourages controlled components.
14. Context API: Global State Without Prop Drilling
const ThemeContext = createContext();
Used for:
- Themes
- Auth state
- Language settings
Not a replacement for Redux—just scoped global state.
15. State Management Architecture
For large apps:
Options:
- React Context
- Redux Toolkit
- Zustand
- Recoil
Typical architecture:
UI Components
↓
State Layer
↓
Business Logic
↓
API / Backend
16. Side Effects & Data Fetching
React itself does not fetch data.
You use:
fetchaxiosReact QuerySWR
Best practice:
- Keep side effects out of render logic
- Use effects or external data layers
17. Performance Optimization in React
Key techniques:
React.memouseMemouseCallback- Avoid unnecessary re-renders
- Proper key usage
- Component splitting
18. React Is Not a Framework
React handles:
- UI
- State
- Rendering
It does NOT include:
- Routing
- Data fetching
- File structure
- Build system
Frameworks built on React:
- Next.js
- Remix
- Gatsby
19. Mental Model You Must Understand
React is:
- A state machine
- Rendering is deterministic
- UI is a snapshot of state
- Re-render ≠ DOM update
If you understand this, React becomes simple.
20. Final Thoughts
React is not hard.
What makes React difficult is:
- Thinking imperatively
- Fighting the data flow
- Not understanding rendering
Once you embrace:
- Declarative UI
- Component composition
- State-driven rendering
React becomes one of the most powerful tools in modern software engineering.
Top comments (0)