箭头函数(=>)是用于编写函数表达式的简短语法。这些函数允许正确绑定组件的上下文,因为在 ES6 中默认下不能使用自动绑定。使用高阶函数时,箭头函数非常有用。
1//General way
2render() {
3 return(
4 <MyInput onChange = {this.handleChange.bind(this) } />
5 );
6}
7//With Arrow Function
8render() {
9 return(
10 <MyInput onChange = { (e)=>this.handleOnChange(e) } />
11 );
12}
箭头函数(=>)是用于编写函数表达式的简短语法。这些函数允许正确绑定组件的上下文,因为在 ES6 中默认下不能使用自动绑定。使用高阶函数时,箭头函数非常有用。
1//General way
2render() {
3 return(
4 <MyInput onChange = {this.handleChange.bind(this) } />
5 );
6}
7//With Arrow Function
8render() {
9 return(
10 <MyInput onChange = { (e)=>this.handleOnChange(e) } />
11 );
12}