Skip to content

Instantly share code, notes, and snippets.

@forivall
Created October 10, 2019 00:32
Show Gist options
  • Save forivall/8307ff94af61511c028d6c06e99c06e3 to your computer and use it in GitHub Desktop.
Save forivall/8307ff94af61511c028d6c06e99c06e3 to your computer and use it in GitHub Desktop.
React hook for unique ids for htmlFor
let labelForId = 0;
export default const useInputId = () => {
const labelId = React.useRef(() => labelForId++);
return `my-input-${labelId.current}`;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment