@byteclaw/use-unique-id
v1.0.2
Published
React hook to generate unique ids for your components
Downloads
59
Readme
@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>
);
}