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