Tsallaka zuwa abun ciki
Justice Tech School

Pure Components

A pure component returns the same JSX for the same props and state and does not change outside values while rendering. This lets React render safely and in any order.

Example
const double = (n) => n * 2; // pure
let total = 0;
const impure = (n) => (total += n); // changes outside
console.log(double(3), double(3));
console.log(impure(3), impure(3));

Result

6 6
3 6

Exercise

Pure functions give the same ___ for the same input.

Same input, same 

Quiz Test

What makes a render impure?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.