Pure Components & Avoiding Side Effects in Render
Write render functions that are free of mutations and external reads.
Pure Components & Avoiding Side Effects in Render is a free React Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the React Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Welcome
What Is a Pure Function?
Why Purity Matters in React
Common Impurity: Mutating External State
let totalRenders = 0; // external
function Counter() {
totalRenders++; // BAD: side effect in render
return <p>{totalRenders}</p>;
}Common Impurity: Mutating Props
// Bad
function Badge({ user }) {
user.name = user.name.toUpperCase(); // mutates prop!
return <p>{user.name}</p>;
}
// Good
function Badge({ user }) {
const displayName = user.name.toUpperCase();
return <p>{displayName}</p>;
}Common Impurity: Using Random / Date in Render
// Bad
function Token() {
const id = Math.random(); // different every render!
return <p>{id}</p>;
}
// Good
function Token() {
const [id] = useState(() => Math.random());
return <p>{id}</p>;
}API Calls Belong in useEffect
// Bad
function Profile({ id }) {
fetch('/api/user/' + id); // runs on every render!
return <div />;
}
// Good
useEffect(() => {
fetch('/api/user/' + id).then(/*...*/);
}, [id]);Local Mutations Are Fine
function List({ items }) {
const sorted = [...items]; // new array
sorted.sort(); // mutating a local copy: OK
return sorted.map(i => <li key={i}>{i}</li>);
}Using Strict Mode to Find Impurities
Pure Components and React.memo
const Pure = React.memo(function Pure({ value }) {
return <p>{value}</p>;
});Quick Check
Recap
Up Next
Frequently asked questions
Is the “Pure Components & Avoiding Side Effects in Render” lesson free?
Yes — the full text of “Pure Components & Avoiding Side Effects in Render” is free to read here on the web, and the React Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the React Academy course, upgrade to CoddyKit PRO.
What will I learn in “Pure Components & Avoiding Side Effects in Render”?
Write render functions that are free of mutations and external reads. You practise React Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start React Academy?
No prior experience is required. React Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Pure Components & Avoiding Side Effects in Render” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this React Academy lesson?
Yes. Every React Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- What StrictMode Does
- Pure Components & Avoiding Side Effects in Render
- Key & Ref Best Practices
- Folder Structure & Naming Conventions