DEV Community

Discussion on: useDumbHooks

Collapse
 
stereobooster profile image
stereobooster

Wrote today

const useUniqueId = () => {
  const id = React.useRef<string>(null);
  if (!id.current) id.current = nanoid();
  return id.current;
}
Collapse
 
alutom profile image
alutom
const useUniqueId = () => React.useState(nanoid)[0];
Collapse
 
stereobooster profile image
stereobooster • Edited

This is quite smart and more idiomatic than my version. Write more