1 | 'use client';
|
2 |
|
3 | import * as React from 'react';
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | export function useRootElementName(parameters) {
|
10 | const {
|
11 | rootElementName: rootElementNameProp = '',
|
12 | componentName
|
13 | } = parameters;
|
14 | const [rootElementName, setRootElementName] = React.useState(rootElementNameProp.toUpperCase());
|
15 | if (process.env.NODE_ENV !== 'production') {
|
16 |
|
17 | React.useEffect(() => {
|
18 | if (rootElementNameProp && rootElementName !== rootElementNameProp.toUpperCase()) {
|
19 | 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');
|
20 | }
|
21 | }, [rootElementNameProp, rootElementName, componentName]);
|
22 | }
|
23 | const updateRootElementName = React.useCallback(instance => {
|
24 | var _instance$tagName;
|
25 | setRootElementName((_instance$tagName = instance == null ? void 0 : instance.tagName) != null ? _instance$tagName : '');
|
26 | }, []);
|
27 | return [rootElementName, updateRootElementName];
|
28 | } |
\ | No newline at end of file |