I have form elements with label
s and I want to have unique IDs to link label
s to elements with htmlFor
attribute. Something like this:
React.createClass({
render() {
const id = ???;
return (
<label htmlFor={id}>My label</label>
<input id={id} type="text"/>
);
}
});
I used to generate IDs based on this._rootNodeID
but it’s unavailable since React 0.13. What is the best and/or simplest way to do it now?
如果不需要,请不要使用ID,而是将输入内容包装在这样的标签中:
这样,您就不必担心唯一ID。