Debian Codegraph @

node/@patternfly/react-core/dist/js/helpers/useSSRSafeId.js

raw
1 "use strict";
2 Object.defineProperty(exports, "__esModule", { value: true });
3 exports.useSSRSafeId = void 0;
4 const react_1 = require("react");
5 const reactUseId = typeof react_1.useId === 'function' ? react_1.useId : undefined;
6 let counter = 0;
7 /**
8 * SSR-safe ID generation hook. Uses React.useId() when available (React 18+)
9 * for guaranteed SSR/CSR match. Falls back to a counter-based approach for React 17.
10 */
11 exports.useSSRSafeId = reactUseId
12 ? function useSSRSafeId(prefix = 'pf-') {
13 return `${prefix}${reactUseId()}`;
14 }
15 : function useSSRSafeId(prefix = 'pf-') {
16 const [id] = (0, react_1.useState)(() => `${prefix}${++counter}`);
17 return id;
18 };
19 //# sourceMappingURL=useSSRSafeId.js.map