π§© Component-Based Architecture
The UI is divided into small, reusable pieces called components (e.g., buttons, forms, cards).
Each component manages its own state and logic, making development modular and maintainable.
<div class="infographic-housereact" id="hr">
<style>
.infographic-housereact {
--ink: #1a1a1a;
--ink-soft: #5c5c5c;
--paper: #ffffff;
--paper-alt: #f0ece4;
--accent: #2563eb;
--accent-deep: #1942a8;
--accent-soft: #e3ebfd;
--line: #ddd6c9;
--radius: 8px;
--display-font: 'Fraunces', Georgia, serif;
--body-font: 'Inter', system-ui, sans-serif;
--mono-font: 'IBM Plex Mono', monospace;
max-width: 880px;
padding: 2rem;
margin: 0 auto;
box-sizing: border-box;
background: transparent;
color: var(--ink);
font-family: var(--body-font);
}
.infographic-housereact[data-theme="dark"] {
--ink: #e8e6e1;
--ink-soft: #9a968c;
--paper: #13171f;
--paper-alt: #1c212b;
--accent: #5b8def;
--accent-deep: #8fb4ff;
--accent-soft: #20293f;
--line: #2c313d;
}
.infographic-housereact * { box-sizing: border-box; }
.hr-eyebrow {
font-family: var(--mono-font); font-size: 0.72rem; letter-spacing: 0.1em;
text-transform: uppercase; color: var(--accent); margin: 0 0 0.45rem;
display: flex; align-items: center; justify-content: center; gap: 0.4rem;
}
.hr-eyebrow::before { content: ""; width: 14px; height: 2px; background: var(--accent); display: inline-block; }
.hr-title {
font-family: var(--display-font); font-size: clamp(1.5rem, 4vw, 2.3rem); text-align: center;
margin: 0 0 0.55rem; line-height: 1.12; letter-spacing: -0.01em;
}
.hr-sub {
color: var(--ink-soft); font-size: 0.95rem; max-width: 480px; line-height: 1.55; margin: 0 auto 2rem;
text-align: center;
}
/* ===== Floor plans ===== */
.hr-plans { display: flex; align-items: center; justify-content: center; gap: 1.75rem; flex-wrap: wrap; margin-bottom: 1.3rem; }
.hr-plan { display: flex; flex-direction: column; align-items: center; gap: 0.7rem; }
.hr-box {
display: grid; grid-template-columns: 1fr 1fr; grid-auto-rows: min-content; gap: 3px;
width: 260px; background: var(--paper); border: 2px solid var(--ink); padding: 3px;
}
.hr-room {
font: inherit; font-family: var(--body-font); font-weight: 600; font-size: 0.82rem; color: #fff;
border: none; cursor: pointer; display: flex; align-items: center; justify-content: center;
text-align: center; padding: 0.5rem; height: 108px; line-height: 1.25;
transition: transform 0.15s ease, opacity 0.2s ease, outline-color 0.15s ease;
outline: 3px solid transparent; outline-offset: -3px;
}
.hr-room.hr-wide { grid-column: 1 / -1; height: 128px; }
.hr-room:hover { transform: scale(1.015); }
.hr-room:focus-visible { outline-color: var(--accent); }
.hr-room.is-active { outline-color: var(--accent); transform: scale(1.025); z-index: 1; }
.hr-room.is-dim { opacity: 0.4; }
.hr-vs {
font-family: var(--display-font); font-weight: 600; font-size: 2.4rem; color: var(--ink);
align-self: center;
}
.hr-plan-label { font-size: 0.95rem; font-weight: 600; color: var(--ink); margin: 0; }
.hr-caption {
text-align: center; font-size: 0.9rem; color: var(--ink-soft); min-height: 1.5em;
max-width: 520px; margin: 0 auto 1.6rem; line-height: 1.5; transition: opacity 0.15s ease;
}
@media (max-width: 620px) {
.hr-plans { flex-direction: column; gap: 0.9rem; }
.hr-vs { transform: none; }
.hr-box { width: 100%; max-width: 300px; }
}
.hr-takeaway {
margin-top: 0.5rem; padding: 0.95rem 1.2rem; background: var(--accent-soft);
border-left: 3px solid var(--accent); border-radius: 4px; font-size: 0.9rem; color: var(--ink); line-height: 1.5;
}
.hr-takeaway b { color: var(--accent-deep); }
@media (prefers-reduced-motion: reduce) {
.infographic-housereact *, .infographic-housereact *::before, .infographic-housereact *::after {
transition-duration: 0.001ms !important; animation-duration: 0.001ms !important;
}
}
</style>
<div class="hr-eyebrow">React Fundamentals</div>
<h1 class="hr-title">Think of React Like a House</h1>
<p class="hr-sub">Click a room in either floor plan to see how it maps.</p>
<div class="hr-plans">
<div class="hr-plan">
<div class="hr-box" data-side="house">
<button class="hr-room" data-pair="1" style="background:#c65fd9;">Kitchen</button>
<button class="hr-room" data-pair="2" style="background:#5b3df0;">Bedroom</button>
<button class="hr-room hr-wide" data-pair="3" style="background:#4caf50;">Living Room</button>
</div>
<p class="hr-plan-label">House</p>
</div>
<div class="hr-vs">vs</div>
<div class="hr-plan">
<div class="hr-box" data-side="react">
<button class="hr-room" data-pair="1" style="background:#c65fd9;">Components</button>
<button class="hr-room" data-pair="2" style="background:#5b3df0;">State Management</button>
<button class="hr-room hr-wide" data-pair="3" style="background:#4caf50;">one-way flow of info</button>
</div>
<p class="hr-plan-label">React JS</p>
</div>
</div>
<p class="hr-caption" id="hrCaption">Click a room to see how it maps to React.</p>
<div class="hr-takeaway"><b>Same shape, different bricks</b> β rooms become components, all wired together by one flow of data.</div>
</div>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link href="https://fonts.googleapis.com/css2?family=Fraunces:wght@500;600&family=Inter:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500&display=swap" rel="stylesheet">
<script>
(function () {
var root = document.getElementById('hr');
if (!root) return;
/* --- dark mode detection: body attribute > cookie > postMessage > light --- */
function applyDark(dark) {
if (dark) root.setAttribute('data-theme', 'dark');
else root.removeAttribute('data-theme');
}
var bodyAttr = document.body.getAttribute('data-darkmode');
var dark;
if (bodyAttr === 'true') dark = true;
else if (bodyAttr === 'false') dark = false;
else {
var match = document.cookie.match(/(?:^|;\s*)darkMode=([^;]+)/);
dark = match ? match[1] === 'true' : false;
}
applyDark(dark);
window.addEventListener('message', function (e) {
if (e.data && e.data.type === 'darkMode') applyDark(!!e.data.value);
});
/* --- cross-diagram room highlight --- */
var rooms = root.querySelectorAll('.hr-room');
var caption = root.querySelector('#hrCaption');
var defaultCaption = 'Click a room to see how it maps to React.';
var captions = {
'1': 'A kitchen does one job on its own β so does a component.',
'2': 'Your bedroom holds your things β state holds a component\u2019s data.',
'3': 'Everyone passes through the living room β that\u2019s how data flows through the app.'
};
var active = null;
function setActive(pair) {
active = (active === pair) ? null : pair;
rooms.forEach(function (r) {
var match = r.getAttribute('data-pair') === active;
r.classList.toggle('is-active', !!active && match);
r.classList.toggle('is-dim', !!active && !match);
});
caption.textContent = active ? captions[active] : defaultCaption;
}
rooms.forEach(function (r) {
r.addEventListener('click', function () { setActive(r.getAttribute('data-pair')); });
});
})();
</script>The diagram is a visual representation of how a webpage is broken down into different reusable components in React.
π§ JSX (JavaScript XML)
JSX is a syntax extension that lets you write HTML-like code inside JavaScript.
Itβs not mandatory, but widely used in React because it makes code more readable and expressive.
β‘ React implements a virtual DOM for better performance
React uses a virtual DOM, which is a lightweight copy of the real DOM. DOM stands for Document Object Model. It is a programming interface provided by the browser that allows developers to interact with and manipulate the content, structure, and style of a web page.
When something changes, React updates the virtual DOM first, compares it to the previous version (diffing), and updates only the changed part of the actual DOM.
This results in faster performance and better user experience.
π React follows one-way data binding
React follows a unidirectional data flow, meaning data moves from parent to child components.
This makes state changes more predictable and easier to debug.
β Declarative UI
React allows you to describe the UI based on the current state of your application.
It handles updating and rendering the right components when your data changes.
You focus on the "what", and React handles the "how".
πͺ React provides built-in hooks for managing state and side effects
Hooks were introduced in React 16.8.
They let you use state and lifecycle features inside functional components.
Popular hooks include:
useStateβ to manage local stateuseEffectβ to handle side effects (like fetching data)useContext,useRef,useMemo, etc.