Socket
Socket
Sign inDemoInstall

@accessible/use-id

Package Overview
Dependencies
4
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @accessible/use-id

A React hook that creates unique deterministic IDs to facilitate WAI-ARIA and server rendering


Version published
Maintainers
1
Install size
33.9 kB
Created

Changelog

Source

1.1.2 (2021-02-21)

Bug Fixes

  • fix id generation... (008d6b2)

Readme

Source

useId()

Bundlephobia Types Code coverage Build status NPM Version MIT License

npm i @accessible/use-id

Creates unique deterministic IDs to facilitate WAI-ARIA and server rendering. Forked from @reach/auto-id.

Quick Start

import useId from '@accessible/use-id'

const Component = () => {
  const id = useId()
  return <div id={id} />
  // <div id='A:1'>
}

API

useId(fallbackId?: string | null | 0 | false, prefix?: string): string | undefined

A hook that returns a unique, but deterministic ID once per component

Arguments

ArgumentTypeDefaultRequired?Description
fallbackIdstring | null | 0 | falseundefinedNoAllows you to provide your own id as a fallback
prefixstring🅰NoAllows you to provide a prefix for the id to prevent collisions with other auto id libs

Credit

This library is a fork of @reach/auto-id

Why fork?

Reach UI doesn't use real semantic versioning (each of their packages updates versions at the same time regardless of changes to individual packages... nonsense) so it's possible (and annoyingly so) that you could easily wind up with duplicate version of the auto-id package in your bundle. Lastly, the Reach library throws super annoying warnings in SSR because it uses useLayoutEffect. This library uses @react-hook/passive-layout-effect to avoid that.

LICENSE

MIT

Keywords

FAQs

Last updated on 21 Feb 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc