Created
October 10, 2019 00:32
-
-
Save forivall/8307ff94af61511c028d6c06e99c06e3 to your computer and use it in GitHub Desktop.
React hook for unique ids for htmlFor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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