mui/base-ui

[core] Standardize error messages across components

Opened this issue · 0 comments

Create a utility to format a message and show an error to have consistency.
The most common case for now is a missing context. Errors should be handled in hooks (use*Context), optionally allowing the context to be absent, as in:

function useMenuRootContext(optional?: false): MenuRootContext;
function useMenuRootContext(optional: true): MenuRootContext | null;
function useMenuRootContext(optional?: boolean) {
const context = React.useContext(MenuRootContext);
if (context === null && !optional) {
throw new Error('Base UI: MenuRootContext is not defined.');
}
return context;
}

Search keywords: