parent component:
this.state = {
items: ["beijing", "shanghai"]
}
<div>
<List items={this.state.items}
</div>
const List = (items) = > (
)<div>
<ul>
{items.map(item => <li key={item}>{item}</li>}
</ul>
</div>
)
will report an error items.map is not function,. What is the reason for this?
class List extends Component {
render() {
return (
<div>
<ul>
{this.props.items.map(item => <li key={item}>{item}</li>)}
</ul>
</div>
)
}
}
so that no error will be reported.