I am getting this:
Warning: Each child in an array or iterator should have a unique "key" prop.
Here is my code of Dropdown Component:
render() {
let dropDownClasses = [classes["im-dropdown"], classes[this.state.size], classes[this.state.dropStyle], classes[this.status]];
let itemcount = -1;
let options;
if(this.state.options !== undefined){
options = this.state.options.map(option => {
itemcount++;
return(<div><li key ={'opt_'+this.state.name+'_'+itemcount} role="option" aria-selected="false" value={option.value} tabIndex={itemcount} onClick={this.handleSelect.bind(this, this.state.name, option.value, option.text)}> {option.text} </li></div>)
});
}
return (
<div className={dropDownClasses.join(' ')}>
<button aria-haspopup="listbox" aria-expanded="false" onClick={this.handleOpen}>
<span>{this.state.label}</span><span className={classes["caret"]}><i className="fa fa-angle-down"></i></span>
</button>
<ul className={classes["options"]} role="listbox" aria-labelledby={"im-drop_" +this.state.size+"_"+this.state.dropStyle} >
<span key ={'opt_'+this.state.name+'_'+itemcount}>{options} </span>
</ul>
</div>
);
}
and I am calling it through another component as SideDrawer.js like this:
<div>
<span className ={classes["filter"]}><strong>FILTER BY</strong></span>
</div>
<Dropdown key={'opt_'+ clientDropdown.label} label={clientDropdown.label} name={clientDropdown.name} options={clientDropdown.options} action={props.formHandler}/>
<Dropdown label={typeDropdown.label} name={typeDropdown.name} options={typeDropdown.options} action={props.formHandler}/>
<Dropdown label={categoryDropdown.label} name={categoryDropdown.name} options={categoryDropdown.options} action={props.formHandler}/>
</div>
The warning seems to be coming since I am invoking Dropdown components multiple times in a single div (more like an array of items) thereby causing Key warning. I tried to use "key" as a prop but it doesn't _