Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@bscop/use-id

brunoscopelliti79MIT2.0.0TypeScript support: included

A React hook to generate a very-likely unique id, persistent across re-renders.

react, react hook, use id, use-id, hook id, react id, unique id

readme

use-id

GitHub license npm version CircleCI Status Coverage

A React hook to generate a very-likely unique id, persistent across re-renders.

Install

npm i @bscop/use-id

Usage

Default behavior:

import useId from "@bscop/use-id";

useId(); // aS42hp

Custom behavior:

import useId from "@bscop/use-id";

useId({ length: 10, prefix: "app" }); // app-aS42hpZn9Q
  • length: determine the length of the random part of the id (default is 6).

  • prefix: define a prefix that will be prepended to the random id (default, no prefix).

Contribute

Read the guidelines.

Run tests

npm test

Coverage

Coverage reports are hosted on codecov.

npm run badge:coverage -- --token=<guid>

Bruno Scopelliti\ www.brunoscopelliti.com

changelog

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

2.0.0 (2021-05-17)

⚠ BREAKING CHANGES

  • hooks throws an exception when length < 1.

Features

  • validate length is >= 1, when set (401a0df)

1.0.2 (2021-05-11)

1.0.1 (2021-05-06)

1.0.0 (2021-05-05)

Features