Created
October 7, 2017 00:10
-
-
Save che-wf/794a3948ebfd9f5d81dcfc1c204036b3 to your computer and use it in GitHub Desktop.
Allows you to use unique prop ids
This file contains hidden or 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 lastId = 0; | |
export default function(prefix='id') { | |
lastId++; | |
return `${prefix}${lastId}`; | |
} |
This file contains hidden or 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
import newId from 'newid'; | |
React.createClass({ | |
componentWillMount() { | |
this.id = newId(); | |
}, | |
render() { | |
return ( | |
<label htmlFor={this.id}>My label</label> | |
<input id={this.id} type="text"/> | |
); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment