@ryvora/react-id
TypeScript icon, indicating that this package has built-in type declarations

2.0.0Β β€’Β PublicΒ β€’Β Published

ID Generator πŸ†”

Hello, Uniqueness Seeker! πŸ•΅οΈβ€β™€οΈ

The id module, typically providing a useId hook, is your trusty assistant for generating unique IDs within your React components. This is incredibly useful for accessibility (a11y) attributes like aria-labelledby, aria-describedby, or associating labels with form inputs.

It's like a little ID card printer for your components, ensuring everyone has a unique identifier! πŸ’³

Why is it important?

  • Accessibility: Many ARIA attributes require ID references to link elements together (e.g., a custom select trigger to its listbox).
  • Server-Side Rendering (SSR): Ensures that IDs generated on the server match those on the client, preventing hydration mismatches.

Basic Usage

import { useId } from '@ryvora/react-id';

function MyFormControl() {
  const inputId = useId();
  const descriptionId = useId();

  return (
    <div>
      <label htmlFor={inputId}>My Input:</label>
      <input id={inputId} type="text" aria-describedby={descriptionId} />
      <p id={descriptionId}>This is a description for the input.</p>
    </div>
  );
}

Keep your components uniquely identified and accessible! ✨

Package Sidebar

Install

npm i @ryvora/react-id

Weekly Downloads

32

Version

2.0.0

License

MIT

Unpacked Size

9.18 kB

Total Files

9

Last publish

Collaborators

  • xjectro