index.js
import React, { Component } from 'react'
import ReactDOM from 'react-dom'
class App extends Component {
clickHandler = name => {
alert(name)
}
render() {
// 方法1,不推荐,因为每次渲染都传入一个新的监听函数,会造成子组件的重渲浪费
// return <button onClick={() => this.clickHandler('lilei')}>click</button>
// 方法2,推荐
return <button onClick={this.clickHandler.bind(this, 'lilei')}>click</button>
}
}
ReactDOM.render(<App />, document.getElementById('root'))