Skip to main content
Home

Built and signed on GitHub Actions

Utility functions and hooks for a variety of React-style frameworks.

This package works with Node.js, Deno, BrowsersIt is unknown whether this package works with Cloudflare Workers, Bun
It is unknown whether this package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
It is unknown whether this package works with Bun
This package works with Browsers
JSR Score
100%
Published
a year ago (0.4.0)
function createUseIds
createUseIds(
useRef: useRefType<string[]>,
length?: number,
): () => Generator<string>

Creates a hook that will infinitely generate unique IDs that are stable for the lifetime of the component. This is typically used for <label for="..."> and <input id="..."> pairs.

Examples

Example 1

const useIds = createUseIds(useRef);

function MyComponent() {
    const [buttonId, textId] = useIds();

    return <>
        <button id={buttonId}>Click me</button>
        <label for={textId}>Enter text:</label>
        <input id={textId} />
    </>;
}

Parameters

useRef: useRefType<string[]>

The useRef hook.

optional
length: number = 20

The length of the generated IDs.

Return Type

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@lixquid/util-react

Import symbol

import { createUseIds } from "@lixquid/util-react";
or

Import directly with a jsr specifier

import { createUseIds } from "jsr:@lixquid/util-react";

Add Package

pnpm i jsr:@lixquid/util-react
or (using pnpm 10.8 or older)
pnpm dlx jsr add @lixquid/util-react

Import symbol

import { createUseIds } from "@lixquid/util-react";

Add Package

yarn add jsr:@lixquid/util-react
or (using Yarn 4.8 or older)
yarn dlx jsr add @lixquid/util-react

Import symbol

import { createUseIds } from "@lixquid/util-react";

Add Package

vlt install jsr:@lixquid/util-react

Import symbol

import { createUseIds } from "@lixquid/util-react";

Add Package

npx jsr add @lixquid/util-react

Import symbol

import { createUseIds } from "@lixquid/util-react";

Add Package

bunx jsr add @lixquid/util-react

Import symbol

import { createUseIds } from "@lixquid/util-react";