DEV Community

Cover image for React.js Explained Completely: Architecture, Core Concepts, and How Everything Works Together
Farhad Rahimi Klie
Farhad Rahimi Klie

Posted on

React.js Explained Completely: Architecture, Core Concepts, and How Everything Works Together

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)
Enter fullscreen mode Exit fullscreen mode

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)
Enter fullscreen mode Exit fullscreen mode

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>;
}
Enter fullscreen mode Exit fullscreen mode

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>
Enter fullscreen mode Exit fullscreen mode

Is transformed into:

React.createElement("h1", null, "Hello");
Enter fullscreen mode Exit fullscreen mode

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" />
Enter fullscreen mode Exit fullscreen mode
function User({ name }) {
  return <p>{name}</p>;
}
Enter fullscreen mode Exit fullscreen mode

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);
Enter fullscreen mode Exit fullscreen mode

When state changes:

  1. React schedules an update
  2. Component re-renders
  3. Virtual DOM is updated
  4. 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
  };
}, []);
Enter fullscreen mode Exit fullscreen mode

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:

  1. A new Virtual DOM tree is created
  2. React compares it with the old one (diffing)
  3. 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} />
))
Enter fullscreen mode Exit fullscreen mode

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

  1. State change occurs
  2. React schedules update
  3. Fiber builds work units
  4. Virtual DOM comparison
  5. Minimal DOM updates
  6. 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)} />
Enter fullscreen mode Exit fullscreen mode

State controls the UI.

Uncontrolled Input

<input ref={inputRef} />
Enter fullscreen mode Exit fullscreen mode

DOM controls the state.

React encourages controlled components.


14. Context API: Global State Without Prop Drilling

const ThemeContext = createContext();
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

16. Side Effects & Data Fetching

React itself does not fetch data.

You use:

  • fetch
  • axios
  • React Query
  • SWR

Best practice:

  • Keep side effects out of render logic
  • Use effects or external data layers

17. Performance Optimization in React

Key techniques:

  • React.memo
  • useMemo
  • useCallback
  • 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)