Skip to content

Auto ID

Autogenerate IDs to facilitate WAI-ARIA and server rendering.

A string can be supplied as an argument to be useId in lieu of the auto-generated ID. This is handy for accepting user-provided prop IDs that need to be deterministic.

Installation

From the command line in your project directory, run npm install @reach/auto-id or yarn add @reach/auto-id. Then import the useId hook:

npm install @reach/auto-id# oryarn add @reach/auto-id
import { useId } from "@reach/auto-id";

Usage

import { useId } from "@reach/auto-id";
// Pass in a user-supplied ID that will be used conditionally if providedconst id = useId(props.id);