Challenge - 5 Problems
React Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate2:00remaining
Why does React use a virtual DOM?
React uses a virtual DOM to improve performance. What does the virtual DOM do?
Attempts:
2 left
💡 Hint
Think about how React makes updates faster without changing the whole page.
✗ Incorrect
React creates a virtual DOM, which is a lightweight copy of the real DOM. It compares changes in the virtual DOM first, then updates only the parts of the real DOM that changed. This makes updates faster and smoother.
❓ component_behavior
intermediate2:00remaining
What happens when React state changes?
In React, when you update a component's state using useState, what happens next?
Attempts:
2 left
💡 Hint
Think about how React updates the UI efficiently when data changes.
✗ Incorrect
When state changes, React re-renders the component that owns the state. It updates the UI to reflect the new state without reloading the whole page.
📝 Syntax
advanced2:00remaining
Which React hook is used to perform side effects?
You want to run code after a React component renders, like fetching data. Which hook should you use?
Attempts:
2 left
💡 Hint
This hook runs after rendering and can watch for changes.
✗ Incorrect
useEffect runs side effects after rendering, such as fetching data or updating the document title.
🔧 Debug
advanced2:00remaining
Why does this React component not update on button click?
Look at this React component code. Why does clicking the button not update the displayed count?
function Counter() {
let count = 0;
return (
);
}
Count: {count}
React
function Counter() { let count = 0; return ( <div> <p>Count: {count}</p> <button onClick={() => { count += 1; }}>Increase</button> </div> ); }
Attempts:
2 left
💡 Hint
React only re-renders when state or props change.
✗ Incorrect
The count variable is a normal variable that resets on every render. React does not track it as state, so changes to it do not cause re-rendering.
❓ lifecycle
expert2:00remaining
When does React run cleanup functions in useEffect?
Consider this React useEffect hook:
useEffect(() => {
const id = setInterval(() => console.log('tick'), 1000);
return () => clearInterval(id);
}, []);
When is the cleanup function called?
React
useEffect(() => {
const id = setInterval(() => console.log('tick'), 1000);
return () => clearInterval(id);
}, []);Attempts:
2 left
💡 Hint
Think about when React cleans up effects with empty dependency arrays.
✗ Incorrect
With an empty dependency array, the effect runs once on mount, and the cleanup runs only when the component unmounts.