I use React.createElement
to create elements with dynamic view:
{list && list.length !== 0 ?
list.map((model, i) =>
React.createElement(ListRow, {
key: i,
model,
...rowProps,
onEdit: () => this.onEdit(model),
onDelete: () => this.onDelete(model)
})) : null
}
This works fine for me, but I get this warning in console:
Warning: Each child in an array or iterator should have a unique "key" prop. See *here shold be link* for more information.
in EditableList (created by Connect(EditableList))
in Connect(EditableList) (created by CreateInvoiceFormView)
I get this warning even if list.length === 0
< and have no idea why this happens.
I've tried to generate id's, that didn't help.
Here is whole component code:
class EditableList extends Component {
componentWillMount() {
const {name, dispatch} = this.props;
dispatch(createList(name));
}
componentWillUnmount() {
const {name, dispatch} = this.props;
dispatch(destroyList(name));
}
onAdd(item) {
const {dispatch, name} = this.props;
dispatch(openPopup(name, item));
}
onEdit(item) {
const {dispatch, name} = this.props;
dispatch(editItem(name, item));
dispatch(openPopup(name, item));
}
onDelete(item) {
const {dispatch, name} = this.props;
dispatch(deleteItem(name, item));
}
render() {
const {ListRow, list, rowProps, title} = this.props;
return [
<SectionTitleView title={title} add onClick={() => this.onAdd()}/>,
<div>{list && list.length !== 0 ? list.map((model, i) =>
React.createElement(ListRow, {
key: i,
model,
...rowProps,
onEdit: () => this.onEdit(model),
onDelete: () => this.onDelete(model)
})) : null
}
</div>];
}
}
I searched for this problem in here on stack by couldn't fing anything similar, and I have no idea what am I doing wrong. Please let me know, if I don't provide enough information for this issue.