Why should rendering avoid mutating props or external state?

React fundamentalsFoundations & codingAbout 9 minutes

Understand the idea, explain it in your own words and use the rubric to find your next learning gap.

Local drafts · no account or AI calls
Sukoaa original

The idea behind the question

React may run rendering more than once or abandon work before committing it. A render calculation should derive UI from its inputs without changing data owned elsewhere.

AN ILLUSTRATIVE EXAMPLE

A component sorts its props array in place, changing the order seen by a sibling even before the user clicks anything.

TRY A SMALL EXAMPLEJavaScript · standalone helper
// Standalone helper: run in JavaScript; apply the idea in React.
const products = [{ id: 1, price: 20 }, { id: 2, price: 10 }];
const byPrice = items => [...items].sort((a, b) => a.price - b.price);
console.log(JSON.stringify(byPrice(products).map(p => p.id)));
console.log(JSON.stringify(byPrice(products).map(p => p.id)));
console.log(JSON.stringify(products.map(p => p.id)));
Show expected output
[2,1]
[2,1]
[1,2]
Open JavaScript playground

Copy and paste to run in a separate tab. This example illustrates one concept; it is not a complete application or an automatically graded task.

A practical way to learn it

Write a pure helper that sorts products by price without mutating its input. Run it twice and verify that the original order remains unchanged.

Open React project studio

The related tool opens separately; your interview answer stays here. Written practice is self-guided, without automatic code grading.

Build an explanation you understand

  1. State what the concept does in plain language.
  2. Apply it to the example and make your assumptions explicit.
  3. Explain a trade-off, failure case and how you would test it.
  4. Distinguish your actual experience from a proposed approach.

Further reading

Further-reading links support learning; the reference is Sukoaa-authored, not an official employer answer key.