0
0
Reactframework~20 mins

Managing large applications in React - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Master of Managing Large React Apps
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
How does code splitting affect a React app's initial load?

Consider a large React app using code splitting with React.lazy and Suspense. What is the main effect on the app's initial load?

React
const LazyComponent = React.lazy(() => import('./HeavyComponent'));

function App() {
  return (
    <React.Suspense fallback={<div>Loading...</div>}>
      <LazyComponent />
    </React.Suspense>
  );
}
AThe initial load time is unaffected because code splitting only works on server side.
BThe initial load is slower because all code is bundled together and loaded at once.
CThe app crashes because lazy loading is not supported in React.
DThe initial load is faster because only essential code is loaded first, and heavy parts load later.
Attempts:
2 left
💡 Hint

Think about how loading parts of the app only when needed can help speed up the start.

state_output
intermediate
2:00remaining
What is the final state after multiple context updates?

Given a React context managing a counter, what is the final value of count after these updates?

React
const CountContext = React.createContext();

function CounterProvider({ children }) {
  const [count, setCount] = React.useState(0);

  React.useEffect(() => {
    setCount(c => c + 1);
    setCount(c => c + 1);
    setCount(c => c + 1);
  }, []);

  return <CountContext.Provider value={count}>{children}</CountContext.Provider>;
}

function Display() {
  const count = React.useContext(CountContext);
  return <div>{count}</div>;
}
A3
B1
C0
DNaN
Attempts:
2 left
💡 Hint

Remember that using the updater function form of setState batches updates correctly.

🔧 Debug
advanced
2:00remaining
Why does this React app freeze on large state updates?

This React app freezes when updating a large list in state. What is the main cause?

React
function LargeList() {
  const [items, setItems] = React.useState(Array(100000).fill(0));

  function updateItems() {
    const newItems = items.map(x => x + 1);
    setItems(newItems);
  }

  return <button onClick={updateItems}>Update</button>;
}
AThe entire large array is recreated and causes slow rendering on each update.
BReact does not support arrays larger than 1000 items in state.
CThe button's onClick handler is not properly bound, so updateItems is never called.
DThe map function mutates the original array causing infinite loops.
Attempts:
2 left
💡 Hint

Think about what happens when you create a new large array and React re-renders.

📝 Syntax
advanced
2:00remaining
Which option correctly uses React's useContext with TypeScript?

Given a React context with a default value, which code correctly accesses the context value in a functional component using TypeScript?

React
const UserContext = React.createContext<{name: string} | null>(null);

function UserName() {
  // Access context here
}
A
const user = React.useContext(UserContext);
return &lt;div&gt;{user.name}&lt;/div&gt;;
B
const user = React.useContext(UserContext)!;
return &lt;div&gt;{user.name}&lt;/div&gt;;
C
const user = React.useContext(UserContext) ?? {name: 'Guest'};
return &lt;div&gt;{user.name}&lt;/div&gt;;
D
const user = React.useContext(UserContext) as {name: string};
return &lt;div&gt;{user.name}&lt;/div&gt;;
Attempts:
2 left
💡 Hint

Consider how to safely assert the context is not null when you know it will be provided.

🧠 Conceptual
expert
2:00remaining
What is the main benefit of using a state management library like Redux in large React apps?

In very large React applications, why do developers often choose to use Redux or similar libraries?

ATo automatically optimize rendering performance without any code changes.
BTo replace React's built-in state and context APIs completely for all components.
CTo centralize and organize application state, making it easier to manage and debug complex state changes.
DTo avoid writing any reducer functions or actions manually.
Attempts:
2 left
💡 Hint

Think about how managing state across many components can get complicated.