React基础__JSX语法进阶
JSX语法两种数组的声明方式:
1)第一种,在组件中遍历数组
<script>
let names=['web-react','web','react']
var Component = React.createClass({
render: function () {
return <div>
{
names.map(function(name) {
return <div key={name}>hello {name}</div>
})
}
</div>
}
})
ReactDOM.render(
<Component />,
document.getElementById('app')
)
</script>
2)第二种,在数组中遍历
<script>
let arr=[
<h1 key='key1'>hello web-react</h1>,
<h2 key='key2'>hello web</h2>
]
ReactDOM.render(
<div>{arr}</div>,
document.getElementById('app')
)
</script>