key has been set in the context of a parent component. Must be called during component initialisation.
Signature
Parameters
The key to check for in parent component contexts.
Returns
Returns
true if a parent component has set a context with this key, false otherwise.Example
Conditional Context Usage
Parent Component With Context
Parent Component Without Context
Optional Context Pattern
Library Context Pattern
Notes
- Must be called during component initialisation (not in callbacks or effects)
- Use this to provide fallback values when context may not be available
- Useful for creating reusable components that work both with and without context
- Helps avoid errors when accessing context that might not exist