@mui/base
Version:
MUI Base is a library of headless ('unstyled') React components and low-level hooks. You gain complete control over your app's CSS and accessibility features.
33 lines (32 loc) • 1.49 kB
JavaScript
'use client';
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.useRootElementName = useRootElementName;
var React = _interopRequireWildcard(require("react"));
/**
* @ignore - do not document.
*
* Use this function determine the host element correctly on the server (in a SSR context, for example Next.js)
*/
function useRootElementName(parameters) {
const {
rootElementName: rootElementNameProp = '',
componentName
} = parameters;
const [rootElementName, setRootElementName] = React.useState(rootElementNameProp.toUpperCase());
if (process.env.NODE_ENV !== 'production') {
// eslint-disable-next-line react-hooks/rules-of-hooks
React.useEffect(() => {
if (rootElementNameProp && rootElementName !== rootElementNameProp.toUpperCase()) {
console.error(`useRootElementName: the \`rootElementName\` prop of ${componentName ? `the ${componentName} component` : 'a component'} expected the '${rootElementNameProp}' element, but a '${rootElementName.toLowerCase()}' was rendered instead`, 'This may cause hydration issues in an SSR context, for example in a Next.js app');
}
}, [rootElementNameProp, rootElementName, componentName]);
}
const updateRootElementName = React.useCallback(instance => {
setRootElementName(instance?.tagName ?? '');
}, []);
return [rootElementName, updateRootElementName];
}
;