pre-installations and preparations
This commit is contained in:
1 parent
3e5a0329cb
commit
201d621ac3
6977 files changed
+742826
No files matched your search
+35
@@ -0,0 +1,35 @@
|
||||
"use strict";
|
||||
'use client';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.useRootElementName = useRootElementName;
|
||||
var React = _interopRequireWildcard(require("react"));
|
||||
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
||||
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
||||
/**
|
||||
* @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 => {
|
||||
var _instance$tagName;
|
||||
setRootElementName((_instance$tagName = instance == null ? void 0 : instance.tagName) != null ? _instance$tagName : '');
|
||||
}, []);
|
||||
return [rootElementName, updateRootElementName];
|
||||
}
|
||||
Reference in new issue
Block a user