0
0
Reactframework~20 mins

Single Page Application concept in React - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
SPA Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What happens when you click a navigation link in a React SPA?

In a React Single Page Application (SPA), clicking a navigation link usually does not reload the whole page. What is the main behavior you observe?

AThe browser reloads the entire page and fetches all resources again.
BOnly the URL changes and React updates the visible content without a full page reload.
CThe browser opens a new tab with the linked page.
DThe page content disappears and stays blank until manually refreshed.
Attempts:
2 left
💡 Hint

Think about how SPAs avoid full page reloads to make navigation faster.

state_output
intermediate
2:00remaining
What is the output after state update in a React SPA component?

Consider this React component snippet inside a SPA:

const [count, setCount] = useState(0);

function increment() {
  setCount(count + 1);
}

increment();
increment();
console.log(count);

What will console.log(count) output immediately after calling increment() twice?

React
const [count, setCount] = useState(0);

function increment() {
  setCount(count + 1);
}

increment();
increment();
console.log(count);
A2
B1
CThrows an error
D0
Attempts:
2 left
💡 Hint

Remember that state updates in React are asynchronous and do not immediately change the variable.

📝 Syntax
advanced
2:00remaining
Which React Router code correctly defines a SPA route?

In React Router v6, which code snippet correctly defines a route that renders HomePage component at path /home?

A<Route path="/home" render={() => <HomePage />} />
B<Route path="/home" component={HomePage} />
C<Route path="/home" element={<HomePage />} />
D<Route path="/home" children={<HomePage />} />
Attempts:
2 left
💡 Hint

React Router v6 uses the element prop to specify the component to render.

🔧 Debug
advanced
2:00remaining
Why does this React SPA component cause an infinite render loop?

Look at this React component code:

function Counter() {
  const [count, setCount] = useState(0);
  useEffect(() => {
    setCount(count + 1);
  });
  return <div>Count: {count}</div>;
}

Why does this cause an infinite render loop?

React
function Counter() {
  const [count, setCount] = useState(0);
  useEffect(() => {
    setCount(count + 1);
  });
  return <div>Count: {count}</div>;
}
ABecause useEffect runs after every render and updates state without a dependency array, causing continuous re-renders.
BBecause setCount is called outside useEffect, causing immediate infinite updates.
CBecause count is not initialized properly with useState.
DBecause the component returns invalid JSX syntax.
Attempts:
2 left
💡 Hint

Think about how useEffect dependencies control when the effect runs.

🧠 Conceptual
expert
2:00remaining
What is the main advantage of a Single Page Application over traditional multi-page apps?

Choose the best explanation for why SPAs are often preferred over traditional multi-page applications.

ASPAs load the entire app once and update content dynamically, resulting in faster navigation and smoother user experience.
BSPAs require less JavaScript and are easier to build than multi-page apps.
CSPAs do not use URLs, so they avoid browser history issues.
DSPAs always have better SEO than multi-page apps without extra configuration.
Attempts:
2 left
💡 Hint

Think about how SPAs handle page changes compared to full reloads.