(deterministicId?: string)
| 6 | let count = 0 |
| 7 | |
| 8 | function useId(deterministicId?: string): string { |
| 9 | const [id, setId] = React.useState<string | undefined>(useReactId()) |
| 10 | // React versions older than 18 will have client-side ids only. |
| 11 | useIsomorphicLayoutEffect(() => { |
| 12 | if (!deterministicId) setId(reactId => reactId ?? String(count++)) |
| 13 | }, [deterministicId]) |
| 14 | return deterministicId || (id ? `ea-ui-${id}` : '') |
| 15 | } |
| 16 | |
| 17 | export { useId } |