0
0
Reactframework~20 mins

Why React is used - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
React Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why does React use a virtual DOM?
React uses a virtual DOM to improve performance. What does the virtual DOM do?
AIt updates the real DOM directly every time a change happens.
BIt removes the real DOM and uses only JavaScript objects.
CIt creates a copy of the real DOM to find changes before updating the real DOM.
DIt delays all updates until the user refreshes the page.
Attempts:
2 left
💡 Hint
Think about how React makes updates faster without changing the whole page.
component_behavior
intermediate
2:00remaining
What happens when React state changes?
In React, when you update a component's state using useState, what happens next?
AReact re-renders only the component with the updated state.
BNothing happens until you manually refresh the page.
CReact deletes the component and creates a new one from scratch.
DThe entire page reloads to show the new state.
Attempts:
2 left
💡 Hint
Think about how React updates the UI efficiently when data changes.
📝 Syntax
advanced
2: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?
AuseEffect
BuseState
CuseMemo
DuseCallback
Attempts:
2 left
💡 Hint
This hook runs after rendering and can watch for changes.
🔧 Debug
advanced
2: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>
  );
}
AThe button's onClick handler syntax is incorrect and causes an error.
BThe count variable is not a state, so React does not re-render when it changes.
CThe count variable is declared with let instead of const, causing a syntax error.
DReact components cannot have variables inside the function body.
Attempts:
2 left
💡 Hint
React only re-renders when state or props change.
lifecycle
expert
2: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);
}, []);
ANever, because the dependency array is empty.
BEvery time the component re-renders, before running the effect again.
CImmediately after the effect runs for the first time.
DOnly when the component unmounts from the page.
Attempts:
2 left
💡 Hint
Think about when React cleans up effects with empty dependency arrays.