Skip to content

Instantly share code, notes, and snippets.

@che-wf
Created October 7, 2017 00:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save che-wf/794a3948ebfd9f5d81dcfc1c204036b3 to your computer and use it in GitHub Desktop.
Save che-wf/794a3948ebfd9f5d81dcfc1c204036b3 to your computer and use it in GitHub Desktop.
Allows you to use unique prop ids
let lastId = 0;
export default function(prefix='id') {
lastId++;
return `${prefix}${lastId}`;
}
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