Props (short for properties) are read-only inputs that are passed from one component to another in React.
They are used to send data from a parent component to a child component.
You can think of props like arguments you pass into a function — but here, you pass them into components.
🧠 Key Points
Props are read-only.
Props help make components dynamic and reusable.
Props are passed using JSX attributes.
🟩 What Are We Doing?
You're passing props (data) from a parent component to a child component, and the child component retrieves (accesses) those props to display or use them.
✅ How to Retrieve Props in Functional Components
<div class="infographic-propsexample" id="pe">
<style>
.infographic-propsexample {
--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;
margin: 0 auto;
box-sizing: border-box;
background: transparent;
color: var(--ink);
font-family: var(--body-font);
}
.infographic-propsexample[data-theme="dark"] {
--ink: #e8e6e1;
--ink-soft: #9a968c;
--paper: #13171f;
--paper-alt: #1c212b;
--accent: #5b8def;
--accent-deep: #8fb4ff;
--accent-soft: #20293f;
--line: #2c313d;
}
.infographic-propsexample * { box-sizing: border-box; min-width: 0; }
.pe-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;
}
.pe-eyebrow::before { content: ""; width: 14px; height: 2px; background: var(--accent); display: inline-block; }
.pe-title {
font-family: var(--display-font); font-size: clamp(1.5rem, 4vw, 2.3rem); text-align: center;
margin: 0 0 0.5rem; line-height: 1.14; letter-spacing: -0.01em;
}
.pe-sub { color: var(--ink-soft); font-size: 0.95rem; text-align: center; margin: 0 0 1.9rem; }
.pe-code-compare { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; margin-bottom: 1.6rem; }
.pe-code-block { display: flex; flex-direction: column; }
.pe-code-head { display: flex; align-items: center; justify-content: center; gap: 0.4rem; margin-bottom: 0.5rem; }
.pe-code-head svg { width: 15px; height: 15px; flex-shrink: 0; }
.pe-code-name { font-size: 0.8rem; font-weight: 600; color: var(--ink); }
.pe-code-block pre {
margin: 0; background: #0d0d10; border: 1px solid #24252d; border-radius: var(--radius);
padding: 1rem 1.2rem; overflow: auto; max-height: 260px; flex: 1;
}
.pe-code-block code { font-family: var(--mono-font); font-size: 0.76rem; line-height: 1.75; color: #d4d4d8; white-space: pre; }
.tok-kw { color: #c678dd; }
.tok-tag { color: #e06c75; }
.tok-type { color: #61afef; }
.tok-attr { color: #d19a66; }
.tok-str { color: #98c379; }
.tok-expr { color: #56b6c2; }
.tok-punc { color: #6b7280; }
.pe-run-wrap { display: flex; justify-content: center; margin-bottom: 1.9rem; }
.pe-run-btn {
display: flex; align-items: center; gap: 0.5rem; font: inherit; font-weight: 600; font-size: 0.88rem;
color: #fff; background: var(--accent); border: none; border-radius: 100px; padding: 0.65rem 1.5rem;
cursor: pointer; box-shadow: 0 6px 16px -4px rgba(37,99,235,0.45); transition: transform 0.15s, background 0.15s;
}
.pe-run-btn:hover { transform: translateY(-1px); }
.pe-run-btn:active { transform: scale(0.97); }
.pe-run-btn:focus-visible { outline: 2px solid var(--accent-deep); outline-offset: 2px; }
.pe-run-btn.is-reset { background: var(--ink-soft); box-shadow: none; }
.pe-run-btn svg.play { width: 13px; height: 13px; }
.pe-output-label {
font-family: var(--mono-font); font-size: 0.7rem; letter-spacing: 0.1em; text-transform: uppercase;
color: var(--ink-soft); text-align: center; margin: 0 0 0.7rem;
}
.pe-output-placeholder {
border: 1.5px dashed var(--line); border-radius: var(--radius); padding: 2.2rem 1.5rem; text-align: center;
color: var(--ink-soft); font-size: 0.85rem; max-width: 420px; margin: 0 auto;
}
.pe-preview {
display: none; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
max-width: 420px; margin: 0 auto; box-shadow: 0 10px 24px -12px rgba(26,26,26,0.18);
animation: pe-fade-up 0.35s ease;
}
@keyframes pe-fade-up { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.pe-preview-bar { background: #e9e9e9; padding: 0.5rem 0.7rem; display: flex; gap: 0.35rem; }
.pe-preview-bar span { width: 9px; height: 9px; border-radius: 50%; display: block; }
.pe-preview-bar span:nth-child(1) { background: #ff5f56; }
.pe-preview-bar span:nth-child(2) { background: #ffbd2e; }
.pe-preview-bar span:nth-child(3) { background: #27c93f; }
.pe-preview-page { background: #ffffff; padding: 1.9rem 1.4rem; text-align: center; font-family: Times, "Times New Roman", serif; }
.pe-preview-page h1 { font-size: 1.6rem; margin: 0; color: #000; font-weight: bold; }
.pe-output.is-run .pe-output-placeholder { display: none; }
.pe-output.is-run .pe-preview { display: block; }
@media (max-width: 640px) { .pe-code-compare { grid-template-columns: 1fr; } }
.pe-takeaway {
margin-top: 1.9rem; 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; max-width: 620px; margin-left: auto; margin-right: auto;
}
.pe-takeaway b { color: var(--accent-deep); }
@media (prefers-reduced-motion: reduce) {
.infographic-propsexample *, .infographic-propsexample *::before, .infographic-propsexample *::after {
transition-duration: 0.001ms !important; animation-duration: 0.001ms !important;
}
}
</style>
<div class="pe-eyebrow">Props</div>
<p class="pe-sub">See how <code style="font-family:var(--mono-font)">name="Alex"</code> becomes <code style="font-family:var(--mono-font)">props.name</code>.</p>
<div class="pe-code-compare">
<div class="pe-code-block">
<div class="pe-code-head">
<svg viewBox="0 0 16 16" aria-hidden="true"><path d="M6 3 L2 8 L6 13" fill="none" stroke="var(--accent)" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"/><path d="M10 3 L14 8 L10 13" fill="none" stroke="var(--accent)" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"/></svg>
<span class="pe-code-name">App.js</span>
</div>
<pre><code><span class="tok-kw">function</span> <span class="tok-type">App</span><span class="tok-punc">() {</span>
<span class="tok-kw">return</span> <span class="tok-punc"><</span><span class="tok-type">Greeting</span> <span class="tok-attr">name</span><span class="tok-punc">=</span><span class="tok-str">"Alex"</span> <span class="tok-punc">/>;</span>
<span class="tok-punc">}</span>
<span class="tok-kw">export</span> <span class="tok-kw">default</span> <span class="tok-type">App</span><span class="tok-punc">;</span></code></pre>
</div>
<div class="pe-code-block">
<div class="pe-code-head">
<svg viewBox="0 0 16 16" aria-hidden="true"><path d="M6 3 L2 8 L6 13" fill="none" stroke="var(--accent)" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"/><path d="M10 3 L14 8 L10 13" fill="none" stroke="var(--accent)" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"/></svg>
<span class="pe-code-name">Greeting.js</span>
</div>
<pre><code><span class="tok-kw">function</span> <span class="tok-type">Greeting</span><span class="tok-punc">(</span>props<span class="tok-punc">) {</span>
<span class="tok-kw">return</span> <span class="tok-punc"><</span><span class="tok-tag">h1</span><span class="tok-punc">></span>Hello, <span class="tok-punc">{</span>props.name<span class="tok-punc">}!</</span><span class="tok-tag">h1</span><span class="tok-punc">>;</span>
<span class="tok-punc">}</span>
<span class="tok-kw">export</span> <span class="tok-kw">default</span> <span class="tok-type">Greeting</span><span class="tok-punc">;</span></code></pre>
</div>
</div>
<div class="pe-run-wrap">
<button class="pe-run-btn" id="peRunBtn" type="button">
<svg class="play" viewBox="0 0 12 12" aria-hidden="true"><path d="M2.5 1.5v9l7-4.5z" fill="currentColor"/></svg>
<span id="peRunLabel">Run</span>
</button>
</div>
<div class="pe-output-label">Output</div>
<div class="pe-output" id="peOutput">
<div class="pe-output-placeholder">Click Run to see what App renders.</div>
<div class="pe-preview">
<div class="pe-preview-bar"><span></span><span></span><span></span></div>
<div class="pe-preview-page">
<h1>Hello, Alex!</h1>
</div>
</div>
</div>
<div class="pe-takeaway"><b>props.name</b> is just the value of the <code style="font-family:var(--mono-font)">name</code> attribute App passed in — Greeting never hardcodes "Alex," it just reads whatever it's given.</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('pe');
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);
});
/* --- run / reset --- */
var btn = root.querySelector('#peRunBtn');
var label = root.querySelector('#peRunLabel');
var output = root.querySelector('#peOutput');
var hasRun = false;
btn.addEventListener('click', function () {
hasRun = !hasRun;
output.classList.toggle('is-run', hasRun);
btn.classList.toggle('is-reset', hasRun);
label.textContent = hasRun ? 'Reset' : 'Run';
});
})();
</script>🧠 What's Happening?
Apppasses a prop callednamewith value"Alex"toGreeting.Greetingreceives all props in thepropsobject.You access it using:
👉
props.name
🔎 Step-by-Step Explanation
1. You have two components:
App: The parent componentGreeting: The child component
2. In the App component:
<Greeting name="Alex" />You're using the
Greetingcomponent.You are passing a prop named
namewith the value"Alex".This is just like saying:
props = { name: "Alex" }
3. In the Greeting component:
function Greeting(props) {
return <h1>Hello, {props.name}!</h1>;
}propsis an object that holds all the data passed to the component.You access the
nameprop usingprops.name.
✅ Cleaner Way: Destructuring Props
Instead of props.name, you can destructure the props like this:
function Greeting({ name }) {
return <h1>Hello, {name}!</h1>;
}This works the same way but looks cleaner.
✅ How to Retrieve Props in Class Components
<div class="infographic-classprops" id="cp">
<style>
.infographic-classprops {
--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;
margin: 0 auto;
box-sizing: border-box;
background: transparent;
color: var(--ink);
font-family: var(--body-font);
}
.infographic-classprops[data-theme="dark"] {
--ink: #e8e6e1;
--ink-soft: #9a968c;
--paper: #13171f;
--paper-alt: #1c212b;
--accent: #5b8def;
--accent-deep: #8fb4ff;
--accent-soft: #20293f;
--line: #2c313d;
}
.infographic-classprops * { box-sizing: border-box; min-width: 0; }
.cp-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;
}
.cp-eyebrow::before { content: ""; width: 14px; height: 2px; background: var(--accent); display: inline-block; }
.cp-title {
font-family: var(--display-font); font-size: clamp(1.4rem, 4vw, 2.15rem); text-align: center;
margin: 0 0 0.5rem; line-height: 1.18; letter-spacing: -0.01em;
}
.cp-sub { color: var(--ink-soft); font-size: 0.95rem; text-align: center; margin: 0 0 1.9rem; }
.cp-code-compare { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; margin-bottom: 1.6rem; }
.cp-code-block { display: flex; flex-direction: column; }
.cp-code-head { display: flex; align-items: center; justify-content: center; gap: 0.4rem; margin-bottom: 0.5rem; }
.cp-code-head svg { width: 15px; height: 15px; flex-shrink: 0; }
.cp-code-name { font-size: 0.8rem; font-weight: 600; color: var(--ink); }
.cp-code-block pre {
margin: 0; background: #0d0d10; border: 1px solid #24252d; border-radius: var(--radius);
padding: 1rem 1.2rem; overflow: auto; max-height: 280px; flex: 1;
}
.cp-code-block code { font-family: var(--mono-font); font-size: 0.74rem; line-height: 1.75; color: #d4d4d8; white-space: pre; }
.tok-kw { color: #c678dd; }
.tok-tag { color: #e06c75; }
.tok-type { color: #61afef; }
.tok-attr { color: #d19a66; }
.tok-str { color: #98c379; }
.tok-expr { color: #56b6c2; }
.tok-punc { color: #6b7280; }
.tok-comment { color: #7f848e; font-style: italic; }
.cp-run-wrap { display: flex; justify-content: center; margin-bottom: 1.9rem; }
.cp-run-btn {
display: flex; align-items: center; gap: 0.5rem; font: inherit; font-weight: 600; font-size: 0.88rem;
color: #fff; background: var(--accent); border: none; border-radius: 100px; padding: 0.65rem 1.5rem;
cursor: pointer; box-shadow: 0 6px 16px -4px rgba(37,99,235,0.45); transition: transform 0.15s, background 0.15s;
}
.cp-run-btn:hover { transform: translateY(-1px); }
.cp-run-btn:active { transform: scale(0.97); }
.cp-run-btn:focus-visible { outline: 2px solid var(--accent-deep); outline-offset: 2px; }
.cp-run-btn.is-reset { background: var(--ink-soft); box-shadow: none; }
.cp-run-btn svg.play { width: 13px; height: 13px; }
.cp-output-label {
font-family: var(--mono-font); font-size: 0.7rem; letter-spacing: 0.1em; text-transform: uppercase;
color: var(--ink-soft); text-align: center; margin: 0 0 0.7rem;
}
.cp-output-placeholder {
border: 1.5px dashed var(--line); border-radius: var(--radius); padding: 2.2rem 1.5rem; text-align: center;
color: var(--ink-soft); font-size: 0.85rem; max-width: 440px; margin: 0 auto;
}
.cp-preview {
display: none; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
max-width: 440px; margin: 0 auto; box-shadow: 0 10px 24px -12px rgba(26,26,26,0.18);
animation: cp-fade-up 0.35s ease;
}
@keyframes cp-fade-up { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.cp-preview-bar { background: #e9e9e9; padding: 0.5rem 0.7rem; display: flex; gap: 0.35rem; }
.cp-preview-bar span { width: 9px; height: 9px; border-radius: 50%; display: block; }
.cp-preview-bar span:nth-child(1) { background: #ff5f56; }
.cp-preview-bar span:nth-child(2) { background: #ffbd2e; }
.cp-preview-bar span:nth-child(3) { background: #27c93f; }
.cp-preview-page { background: #ffffff; padding: 1.9rem 1.4rem; text-align: center; font-family: Times, "Times New Roman", serif; }
.cp-preview-page h1 { font-size: 1.35rem; margin: 0; color: #000; font-weight: bold; }
.cp-output.is-run .cp-output-placeholder { display: none; }
.cp-output.is-run .cp-preview { display: block; }
@media (max-width: 640px) { .cp-code-compare { grid-template-columns: 1fr; } }
.cp-takeaway {
margin-top: 1.9rem; 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; max-width: 620px; margin-left: auto; margin-right: auto;
}
.cp-takeaway b { color: var(--accent-deep); }
@media (prefers-reduced-motion: reduce) {
.infographic-classprops *, .infographic-classprops *::before, .infographic-classprops *::after {
transition-duration: 0.001ms !important; animation-duration: 0.001ms !important;
}
}
</style>
<div class="cp-eyebrow">Props</div>
<p class="cp-sub">Same idea as before, just through <code style="font-family:var(--mono-font)">this.props</code> now.</p>
<div class="cp-code-compare">
<div class="cp-code-block">
<div class="cp-code-head">
<svg viewBox="0 0 16 16" aria-hidden="true"><path d="M6 3 L2 8 L6 13" fill="none" stroke="var(--accent)" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"/><path d="M10 3 L14 8 L10 13" fill="none" stroke="var(--accent)" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"/></svg>
<span class="cp-code-name">App.js</span>
</div>
<pre><code><span class="tok-comment">// Functional component that renders Greeting</span>
<span class="tok-kw">import</span> <span class="tok-type">Greeting</span> <span class="tok-kw">from</span> <span class="tok-str">'./Greeting'</span><span class="tok-punc">;</span>
<span class="tok-kw">function</span> <span class="tok-type">App</span><span class="tok-punc">() {</span>
<span class="tok-kw">return</span> <span class="tok-punc"><</span><span class="tok-type">Greeting</span> <span class="tok-attr">name</span><span class="tok-punc">=</span><span class="tok-str">"Alex"</span> <span class="tok-attr">age</span><span class="tok-punc">={</span><span class="tok-expr">25</span><span class="tok-punc">} />;</span>
<span class="tok-punc">}</span>
<span class="tok-kw">export</span> <span class="tok-kw">default</span> <span class="tok-type">App</span><span class="tok-punc">;</span></code></pre>
</div>
<div class="cp-code-block">
<div class="cp-code-head">
<svg viewBox="0 0 16 16" aria-hidden="true"><path d="M6 3 L2 8 L6 13" fill="none" stroke="var(--accent)" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"/><path d="M10 3 L14 8 L10 13" fill="none" stroke="var(--accent)" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"/></svg>
<span class="cp-code-name">Greeting.js</span>
</div>
<pre><code><span class="tok-kw">import</span> <span class="tok-type">React</span><span class="tok-punc">, {</span> <span class="tok-type">Component</span> <span class="tok-punc">}</span> <span class="tok-kw">from</span> <span class="tok-str">'react'</span><span class="tok-punc">;</span>
<span class="tok-comment">// Class Component that uses props</span>
<span class="tok-kw">class</span> <span class="tok-type">Greeting</span> <span class="tok-kw">extends</span> <span class="tok-type">Component</span> <span class="tok-punc">{</span>
render<span class="tok-punc">() {</span>
<span class="tok-kw">return</span> <span class="tok-punc">(</span>
<span class="tok-punc"><</span><span class="tok-tag">h1</span><span class="tok-punc">></span>
Hello, <span class="tok-punc">{</span><span class="tok-kw">this</span>.props.name<span class="tok-punc">}!</span> You're <span class="tok-punc">{</span><span class="tok-kw">this</span>.props.age<span class="tok-punc">}</span> years old.
<span class="tok-punc"></</span><span class="tok-tag">h1</span><span class="tok-punc">></span>
<span class="tok-punc">);</span>
<span class="tok-punc">}</span>
<span class="tok-punc">}</span>
<span class="tok-kw">export</span> <span class="tok-kw">default</span> <span class="tok-type">Greeting</span><span class="tok-punc">;</span></code></pre>
</div>
</div>
<div class="cp-run-wrap">
<button class="cp-run-btn" id="cpRunBtn" type="button">
<svg class="play" viewBox="0 0 12 12" aria-hidden="true"><path d="M2.5 1.5v9l7-4.5z" fill="currentColor"/></svg>
<span id="cpRunLabel">Run</span>
</button>
</div>
<div class="cp-output-label">Output</div>
<div class="cp-output" id="cpOutput">
<div class="cp-output-placeholder">Click Run to see what App renders.</div>
<div class="cp-preview">
<div class="cp-preview-bar"><span></span><span></span><span></span></div>
<div class="cp-preview-page">
<h1>Hello, Alex! You're 25 years old.</h1>
</div>
</div>
</div>
<div class="cp-takeaway"><b>this.props</b> works just like the <code style="font-family:var(--mono-font)">props</code> parameter in a function component — it's still just the attributes App passed in, only reached through <code style="font-family:var(--mono-font)">this</code> because a class instance holds it.</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('cp');
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);
});
/* --- run / reset --- */
var btn = root.querySelector('#cpRunBtn');
var label = root.querySelector('#cpRunLabel');
var output = root.querySelector('#cpOutput');
var hasRun = false;
btn.addEventListener('click', function () {
hasRun = !hasRun;
output.classList.toggle('is-run', hasRun);
btn.classList.toggle('is-reset', hasRun);
label.textContent = hasRun ? 'Reset' : 'Run';
});
})();
</script>🧠 How It Works:
Class components receive props using
this.props.Here,
this.props.nameis used to retrieve the value"Alex".
🔍 Step-by-Step Explanation:
🔹 1. App Component
function App() {
return <Greeting name="Alex" age={25} />;
}This is a functional component called
App.It returns a JSX element:
<Greeting name="Alex" age={25} />It’s calling the
Greetingcomponent and passing two props:name="Alex"→ this meansprops.name = "Alex"age={25}→ this meansprops.age = 25
🔹 2. Greeting Class Component
class Greeting extends Component {
render() {
return (
<h1>
Hello, {this.props.name}! You're {this.props.age} years old.
</h1>
);
}
}This is a class component, created by extending
React.Component.Inside the class, there’s a
render()method.This method is required in class components—it tells what to display.
To access props in a class component, you use
this.props.
🔹 3. What is this.props?
thisrefers to the instance of the component class.this.propsis an object that contains all the props passed to this component.this.props.name→ refers to"Alex"this.props.age→ refers to25