Embark on a journey of knowledge! Take the quiz and earn valuable credits.
Take A QuizChallenge yourself and boost your learning! Start the quiz now to earn credits.
Take A QuizUnlock your potential! Begin the quiz, answer questions, and accumulate credits along the way.
Take A Quiz
This chapter dives into how to build rich, interactive UIs
using React — from rendering lists, creating forms, and routing between pages,
to styling components with CSS, Sass, and optimizing performance with
React.memo.
🧠 Why This Chapter
Matters
Once you've mastered components and props, the next step is
building user-friendly interfaces that handle:
This chapter ties together real-world frontend skills that
every React developer must know.
✅ 1. React Lists — Rendering
Collections
React lets you loop through arrays and render
components dynamically.
🔹 Rendering a List of
Items
const
fruits = ['Apple', 'Banana', 'Orange'];
function
FruitList() {
return (
<ul>
{fruits.map((fruit, index) => (
<li
key={index}>{fruit}</li>
))}
</ul>
);
}
✅ Always use a unique key prop
when rendering lists to help React track changes.
🔹 Rendering Components
from Data
const
users = [
{ id: 1, name: 'Alice' },
{ id: 2, name: 'Bob' }
];
function
UserList() {
return (
<ul>
{users.map(user => (
<li key={user.id}>
<UserCard name={user.name} />
</li>
))}
</ul>
);
}
function
UserCard({ name }) {
return <p>User: {name}</p>;
}
✅ 2. React Forms — Handling
Inputs
React uses a controlled component model, where form
data is tied to component state.
🔹 Basic Form with
Controlled Input
function
FormExample() {
const [name, setName] =
useState("");
const handleSubmit = (e) => {
e.preventDefault();
alert(`Submitted: ${name}`);
};
return (
<form onSubmit={handleSubmit}>
<input
value={name}
onChange={(e) =>
setName(e.target.value)}
placeholder="Enter name"
/>
<button
type="submit">Submit</button>
</form>
);
}
✅ Controlled inputs make it easy
to validate and manipulate data in real-time.
🔹 Checkbox, Radio, Select
Field Type |
Example Snippet |
Checkbox |
<input type="checkbox" checked={isChecked}
onChange={handleToggle} /> |
Radio |
<input type="radio" value="male"
checked={gender === 'male'} /> |
Select |
<select value={city}
onChange={handleCity}>...</select> |
✅ 3. React Router — Page
Navigation
React Router enables client-side routing for SPAs
(Single Page Applications).
🔹 Setup
npm
install react-router-dom
🔹 Basic Routing Example
import
{ BrowserRouter, Routes, Route, Link } from 'react-router-dom';
function
App() {
return (
<BrowserRouter>
<nav>
<Link
to="/">Home</Link> |
<Link
to="/about">About</Link>
</nav>
<Routes>
<Route path="/"
element={<Home />} />
<Route path="/about"
element={<About />} />
</Routes>
</BrowserRouter>
);
}
function
Home() {
return <h2>Welcome to Home</h2>;
}
function
About() {
return <h2>About Us</h2>;
}
✅ Link replaces <a> to
avoid page refresh
✅
Routes (v6+) replaces older Switch
✅ 4. React Memo — Optimizing
Performance
React.memo() is a higher-order component that memoizes a
functional component to avoid unnecessary re-renders.
🔹 Without Memo
function
Child({ name }) {
console.log("Child rendered");
return <p>{name}</p>;
}
Every time the parent re-renders, this component does too —
even if name doesn’t change.
🔹 With Memo
const
Child = React.memo(function Child({ name }) {
console.log("Memoized Child
rendered");
return <p>{name}</p>;
});
✅ Only re-renders when props
actually change.
✅ 5. React CSS Styling
🔹 Inline Styling
const
style = {
color: 'blue',
fontSize: '20px'
};
function
StyledText() {
return <h1 style={style}>Styled with
inline CSS</h1>;
}
🔹 External CSS
//
App.css
.title
{
color: green;
font-size: 24px;
}
//
App.js
import
'./App.css';
function
Header() {
return <h1
className="title">Styled with CSS</h1>;
}
✅ Best for larger projects where
styles are reused and modular.
✅ 6. React Sass Styling
Sass allows you to write cleaner, nested, and dynamic
styles.
🔹 Setup Sass
npm
install sass
Rename CSS files to .scss:
//
styles.scss
$primary-color:
#4CAF50;
.title
{
color: $primary-color;
font-weight: bold;
}
jsx
CopyEdit
//
App.js
import
'./styles.scss';
function
Header() {
return <h1
className="title">Sass Styled Header</h1>;
}
✅ Sass allows variables, mixins,
and nesting — ideal for large-scale apps.
✅ Summary Table: Rendering and UI
Topic |
Summary |
Lists |
Use map() to render array-based content |
Forms |
Controlled components sync input with state |
React Router |
Enables client-side navigation |
React Memo |
Memoizes components for performance |
CSS Styling |
Use inline, external CSS, or modules |
Sass Styling |
Write scalable, nested styles using .scss |
React is a JavaScript library for building user interfaces. It’s fast, modular, and backed by Facebook, making it popular for modern frontend development.
Yes. A solid understanding of ES6+ JavaScript (like arrow functions, destructuring, and promises) is essential.
A component is a UI building block; a hook is a function that lets you “hook into” React features inside functional components.
Technically a library, but it’s often considered a framework because it’s used to build entire applications.
useState, useEffect, useContext, useRef, and useMemo are most commonly used.
Yes — but Node.js is typically used for tooling, package management, and running development servers.
✅ Yes — for large, complex apps. But for small to medium apps, Context API and hooks are often enough.
Basic concepts can be learned in a few weeks; becoming proficient depends on how often you build projects and practice.
It depends on your project needs, but React is widely adopted and has a huge community, making it a strong choice.
You
can deploy to services like Vercel, Netlify, or GitHub Pages with just a
few clicks — or use traditional hosting for more control.
Please log in to access this content. You will be redirected to the login page shortly.
LoginReady to take your education and career to the next level? Register today and join our growing community of learners and professionals.
Comments(0)