Use descriptive error messages and appropriate error severity based on component maturity and usage patterns. For newer components, throwing errors is acceptable when constraints are violated. For established components, consider using development-mode warnings instead of throwing errors to avoid breaking existing implementations.
Use descriptive error messages and appropriate error severity based on component maturity and usage patterns. For newer components, throwing errors is acceptable when constraints are violated. For established components, consider using development-mode warnings instead of throwing errors to avoid breaking existing implementations.
When writing error messages:
When deciding error severity:
Example:
// Better error message
if (ctx === null) {
if (process.env.NODE_ENV !== 'production') {
console.warn('Material UI: The Tab component should be used inside a Tabs component');
}
// Provide fallback behavior if possible
return defaultContext;
}
// Instead of throwing:
if (ctx === null) {
throw new Error('Material UI: Tabs component was not found in the tree');
}
This approach balances between guiding developers toward correct usage while maintaining compatibility with existing code that might use components in unexpected ways.
Enter the URL of a public GitHub repository