State Management · Junior · Question 20 of 75
What does useContext(ThemeContext) return if there's no provider above?
- ✓Correct answer: The default value passed to
createContext(defaultValue) - 2
undefined, regardless of the default value - 3It throws an error immediately
Explanation
The default is used when no provider is found up the tree. A common pattern is createContext(null) plus a custom hook useAuth() that throws a clear error if the provider is missing.