React hook to generate unique ids for your components.
npm install @byteclaw/use-unique-id
yarn add @byteclaw/use-unique-id
import { useUniqueId } from '@byteclaw/use-unique-id';
import React, { useCallback } from 'react';
function Element() {
const id = useUniqueId();
}
function App() {
return <Element />;
}
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>
);
}