React · Junior · Question 33 of 75
What does useContext(MyContext) return if there's no provider above the component?
- 1Always
undefined; the default value is ignored - ✓Correct answer: The default value from
createContext(defaultValue) - 3React throws a "Provider is missing" error
Explanation
The default value is used when there's no provider higher in the tree. It's often set to null, with a wrapper hook that throws a clear error: "useAuth must be used within AuthProvider".