Generate a unique identifier for React components, useful when assinging htmlFor and id for label + input combinations
npm install unique-id-mixinUnique Id Mixin by @andrewray
---------------
This ReactJS mixin adds component methods letting you generate unique IDs for
your current component. This is useful when you need to assign for=""
attributes for labels and their respective inputs.
Install
-------
npm install unique-id-mixin --save-dev
Example Usage
-------------
var UniqeIdMixin = require('unique-id-mixin');
var Component = React.createClass({
mixins: [ UniqeIdMixin ],
render: function() {
}
});
The above can be a bit verbose to type, and has the problem that you need to
duplicate the string between each HTML element. There is also a convenience
method that will generate UIDs every other call. The first two calls will
return the same UID, then the next two calls will return a new UID, etc.
API
---
this.getNextUid( identifier:String )
Returns a UID generated using the identifier. If identifier has already
been passed, the cached UID will be returned.
this.getNextHtmlFor()
Returns a UID which changes every other call.