Performance: Rendering elements
This affects how fast the page shows content and how smoothly it updates when users interact.
function List({ items }) { return items.map(item => <div key={item.id}>{item.name}</div>); }
function List({ items }) { return items.map(item => <div>{item.name}</div>); }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Rendering list without keys | Many nodes updated | Multiple reflows | High paint cost | [X] Bad |
| Rendering list with keys | Minimal nodes updated | Single reflow | Low paint cost | [OK] Good |
ReactDOM.render(<h1>Hello</h1>, document.getElementById('root')); uses ReactDOM.render with JSX element and document.getElementById('root'), which is correct.ReactDOM.render(<h1>Hello</h1>, document.getElementById('root')); [OK]const element = <h2>Welcome to React!</h2>;
ReactDOM.render(element, document.getElementById('root'));const element = <h1>Hello World</h1>
ReactDOM.render(element, document.getElementById('root'));<li> items inside a <ul>. Which React code correctly renders this list?const names = ['Anna', 'Bob', 'Cara']; // Choose the correct rendering code
const listItems = names.map(name => <li key={name}>{name}</li>);
ReactDOM.render(<ul>{listItems}</ul>, document.getElementById('root')); uses map with key attribute and renders list correctly. const listItems = names.forEach(name => <li>{name}</li>);
ReactDOM.render(<ul>{listItems}</ul>, document.getElementById('root')); uses forEach which returns undefined. ReactDOM.render(<ul><li>names</li></ul>, document.getElementById('root')); renders literal 'names' text. const listItems = names.map(name => <li>{name}</li>);
ReactDOM.render(<ul>listItems</ul>, document.getElementById('root')); misses {} around listItems, rendering literal 'listItems' text.Pass the test and this pattern moves unknown