Error message :
Source code
class NumberList extends React.components{In found I made a careless mistake : extended a wrong class
render(){
const numbers = this.props.numbers;
const listItems = numbers.map((number) =>
<li key={number.toString()}>
{number}
</li>
);
return (
<ul>{listItems}</ul>
);
}
}
const numbers = [1,2,3,4,5];
ReactDOM.render(
<NumberList numbers={numbers} />,
document.getElementById('root')
);
so I should extends class React.Component but not the incorrect one "React.components" to make this class as an react stateful component.
Correction
class NumberList extends React.Component{
render(){
const numbers = this.props.numbers;
const listItems = numbers.map((number) =>
<li key={number.toString()}>
{number}
</li>
);
return (
<ul>{listItems}</ul>
);
}
}
const numbers = [1,2,3,4,5];
ReactDOM.render(
<NumberList numbers={numbers} />,
document.getElementById('root')
);
No comments :
Post a Comment