Skip to content

Latest commit

 

History

History

use-unique-id

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

@Byteclaw/use-unique-id

React hook to generate unique ids for your components.

Installation

npm install @byteclaw/use-unique-id
yarn add @byteclaw/use-unique-id

Usage

Client side only

import { useUniqueId } from '@byteclaw/use-unique-id';
import React, { useCallback } from 'react';

function Element() {
  const id = useUniqueId();
}

function App() {
  return <Element />;
}

Server side support

In order to have consistent unique ids across client and server side render please provider custom UniqueIdProvider.

import { UniqueIdProvider, useUniqueId } from '@byteclaw/use-unique-id';
import React, { useCallback } from 'react';

function Element() {
  const id = useUniqueId();
}

function App() {
  return (
    <UniqueIdProvider>
      <Element />
    </UniqueIdProvider>
  );
}