UI & Dom
useId
Generate a random ID for memory
Usage
useId generates a random ID that persists during rendering. Hooks are typically used to bind input elements to tags. The generated random id is saved into the ref and will not change unless the component is unloaded.
API
The useId hook accepts two parameters:
id
– the string value returned by defaultgenerateId
– function for generating random IDs
Hook returns a string value, which can be either "id" (if the first argument is passed) or a random id generated using the "generateId" function.
1function useId(id: string, generateId?: () => string): string;
Params
Parameters | Default Value | Type | Description |
---|---|---|---|
id | - | string | The string value returned by default |
generateId | - | () => string | Function to generate a random ID` |
Result
Parameters | Default Value | Type | Description |
---|---|---|---|
id | - | string | Generate a random ID for memory |