Tuesday, May 28, 2024
 Popular · Latest · Hot · Upcoming
118
rated 0 times [  125] [ 7]  / answers: 1 / hits: 47471  / 8 Years ago, tue, january 17, 2017, 12:00:00

Could someone please explain how to fix this error




Warning: flattenChildren(...): Encountered two children with the same
key




I have replicated my code below, but for some reason CodePen is not showing the error.



var FilterOptions = React.createClass({
changeOption: function(type, e) {
var val = e.target.value;
this.props.changeOption(val, type);
},

render: function() {

return (
<div className=filter-options>
<div className=filter-option>
<select id=product name=Product value={this.props.product} onChange={this.changeOption.bind(this, 'product')}>
<option value=''>Product</option>
{this.props.productOptions.map(function(option) {
return (<option key={option} value={option}>{option}</option>)
})}
</select>
</div>
</div>
);
}
});


Codepen



As a secondary question, I am pretty sure my reset is supposed to reset the values of the select boxes but this is also not working and just resetting the rendered results - not sure if this is related to the first problem?



Any help much appreciated


More From » reactjs

 Answers
74

Adding the index as value fixed this. Thanks @azium for your sugegstion.



  <select id=product name=Product value={this.props.product} onChange={this.changeOption.bind(this, 'product')}>
<option value=''>Product</option>
{this.props.productOptions.map(function(option, value) {
return (<option key={value} value={option}>{option}</option>)
})}
</select>

[#59324] Sunday, January 15, 2017, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
savanar

Total Points: 237
Total Questions: 105
Total Answers: 99

Location: Wales
Member since Mon, May 17, 2021
3 Years ago
;