I am learning the "clear" ReactJS (i.e. it is not JSX). This is my simple code:
(() => {
class List extends React.Component{
constructor({tag, attributes, items}){
super({tag, attributes, items})
this.tag = tag
this.attributes = attributes
this.items = items
}
render(){
return React.createElement(this.props.tag, this.props.attributes, items.map(
(n, i) => new React.createElement(ListItem,
{ attributes: { ...n.attributes, key: i }, value: n.value })))
}
}
class ListItem extends React.Component{
constructor({attributes, value}){
super({attributes, value})
this.attributes = attributes
this.value = value
}
render(){
return React.createElement("li", this.props.attributes, this.props.value)
}
}
const items = [
{ attributes: null, value: "A" },
{ attributes: null, value: "B" },
{ attributes: null, value: "C" },
{ attributes: null, value: "D" },
{ attributes: null, value: "E" }
]
const root = document.getElementById("root")
ReactDOM.render(new React.createElement(List, { tag: "ul", attributes: null, items }), root)
})()
Pay attention please: I put into the super the same parameters that I get in the component's constructor. Also I use key for li elements. But I get such errors:
Warning: List(...): When calling super() in
List, make sure to pass up the same props that your component's constructor was passed.Warning: Each child in an array or iterator should have a unique "key" prop.
Check the render method of
List.in ListItem (created by List)
in List
Warning: ListItem(...): When calling super() in
ListItem, make sure to pass up the same props that your component's constructor was passed. Warning: ListItem(...): When calling super() inListItem, make sure to pass up the same props that your component's constructor was passed. Warning: ListItem(...): When calling super() inListItem, make sure to pass up the same props that your component's constructor was passed. Warning: ListItem(...): When calling super() inListItem, make sure to pass up the same props that your component's constructor was passed. Warning: ListItem(...): When calling super() inListItem, make sure to pass up the same props that your component's constructor was passed.
What did I do wrong?