index.js
import React, { Component } from 'react'
import ReactDOM from 'react-dom'
class Bar extends Component {
constructor() {
super()
this.state = {
list: ['Lilei', 'Hanmeimei', 'Lihua'],
}
}
clickHandler = value => {
alert(value)
}
render() {
const btns = this.state.list.map((item, index) => {
return (
<button key={index} onClick={this.clickHandler.bind(this, item)}>
{item}
</button>
)
})
return <div>{btns}</div>
}
}
ReactDOM.render(<Bar />, document.getElementById('root'))