React Context helps share data across many components without passing props down manually at every level.
Click to reveal answer
beginner
How does prop drilling relate to the need for Context?
Prop drilling is when you pass props through many layers just to reach a deep child. Context avoids this by providing data directly to components that need it.
Click to reveal answer
intermediate
Can React Context replace all state management needs?
No, Context is good for global data like themes or user info, but complex state logic might need other tools like Redux or Zustand.
Click to reveal answer
beginner
What is a real-life example of when to use React Context?
Sharing a user’s login status or app theme across many pages without passing props through every component.
Click to reveal answer
beginner
What happens if you don’t use Context and have deeply nested components needing the same data?
You end up passing props through many components that don’t need the data, making code harder to read and maintain.
Click to reveal answer
Why is React Context useful?
ATo fetch data from APIs
BTo style components automatically
CTo create new components
DTo avoid passing props through many layers
✗ Incorrect
React Context helps avoid prop drilling by providing data directly to components that need it.
What is 'prop drilling'?
APassing props through many components unnecessarily
BDrilling holes in components
CUsing props only in parent components
DRemoving props from components
✗ Incorrect
Prop drilling means passing props through many layers even if intermediate components don’t use them.
Which data is best suited for React Context?
ATemporary local state
BGlobal data like user info or theme
CAPI call results only
DComponent styles only
✗ Incorrect
Context is ideal for global data shared across many components.
What happens if you don’t use Context for shared data?
AComponents become faster
BData is shared automatically
CYou must pass props through many components
DYou can’t use props at all
✗ Incorrect
Without Context, you pass props manually through each component layer.
Can React Context replace all state management libraries?
ANo, it’s for simple global data
BYes, it replaces all libraries
COnly for styling
DOnly for API calls
✗ Incorrect
Context is good for simple global data but complex state needs other tools.
Explain why React Context is needed and how it helps with prop drilling.
Think about how data moves in a component tree.
You got /4 concepts.
Describe a real-life example where React Context improves your app’s code.
Consider data used by many parts of your app.
You got /4 concepts.
Practice
(1/5)
1. Why do React developers use Context instead of passing props through many components?
easy
A. To replace state management completely
B. To avoid prop drilling and share data easily across components
C. To make components load faster
D. To write less CSS code
Solution
Step 1: Understand prop drilling problem
Passing props through many layers is tedious and error-prone, called prop drilling.
Step 2: Role of Context in React
Context allows sharing data directly without passing props at every level.
Final Answer:
To avoid prop drilling and share data easily across components -> Option B
Quick Check:
Context avoids prop drilling = C [OK]
Hint: Context avoids passing props through many layers [OK]
Common Mistakes:
Thinking Context makes components faster
Believing Context replaces all state
Confusing Context with styling
2. Which of the following is the correct way to create a React Context?
easy
A. const MyContext = React.Context.create();
B. const MyContext = React.useContext();
C. const MyContext = new Context();
D. const MyContext = React.createContext();
Solution
Step 1: Identify the correct React API for context creation
React provides React.createContext() to create a context object.
Step 2: Check other options for syntax errors
React.useContext() is a hook to consume context, not create it. Others are invalid syntax.
Final Answer:
const MyContext = React.createContext(); -> Option D
Quick Check:
Create context with React.createContext() = A [OK]
Hint: Use React.createContext() to create context [OK]
Common Mistakes:
Using useContext to create context
Trying to instantiate Context with new
Incorrect method names like Context.create
3. Given this React code snippet, what will be the output shown by DisplayUser component?
const UserContext = React.createContext('Guest');
function DisplayUser() {
const user = React.useContext(UserContext);
return <div>Hello, {user}!</div>;
}
function App() {
return (
<UserContext.Provider value="Alice">
<DisplayUser />
</UserContext.Provider>
);
}
medium
A. Hello, undefined!
B. Hello, Guest!
C. Hello, Alice!
D. Error: Context not found
Solution
Step 1: Understand default and provided context values
The default value is 'Guest', but the provider sets value to 'Alice'.
Step 2: Context consumption in DisplayUser
DisplayUser uses useContext to get the current context value, which is 'Alice' from the provider.
Final Answer:
Hello, Alice! -> Option C
Quick Check:
Provider value overrides default = A [OK]
Hint: Provider value overrides default context value [OK]
Common Mistakes:
Assuming default value always shows
Expecting undefined without provider
Thinking useContext throws error if no provider
4. What is wrong with this React code using Context?
useContext requires the context object as an argument, e.g., useContext(ThemeContext).
Step 2: Verify other statements
Context creation outside component is correct. Default value 'light' is valid. Functional components can use hooks.
Final Answer:
useContext is called without context argument -> Option A
Quick Check:
useContext needs context argument = B [OK]
Hint: Always pass context object to useContext() [OK]
Common Mistakes:
Calling useContext() with no arguments
Creating context inside component repeatedly
Thinking default value must be an object
Believing hooks require class components
5. You want to share a user's login status and theme preference across many nested components without passing props at every level. Which approach best solves this problem?
hard
A. Use React Context to provide user and theme data globally
B. Pass user and theme as props through every component manually
C. Store user and theme in local component state only
D. Use CSS variables to store user and theme data
Solution
Step 1: Identify the problem with prop drilling
Passing props manually through many nested components is tedious and error-prone.
Step 2: Use Context for global data sharing
React Context allows sharing data like user login and theme globally without prop drilling.
Step 3: Evaluate other options
Local state is limited to one component. CSS variables cannot store user login info. Passing props manually is inefficient.
Final Answer:
Use React Context to provide user and theme data globally -> Option A
Quick Check:
Context shares global data easily = D [OK]
Hint: Use Context for global shared data like user and theme [OK]
Common Mistakes:
Passing props through every component manually
Trying to store user info in CSS
Using local state for global data
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.