1.箭头函数调用的两种实现:
======方法1==========
//这种调用调的是箭头函数的对象
onFocus = {this._commentsTextGetFocus}
//箭头函数
_commentsTextGetFocus = () => {
if (this.state.commentsText.length > 0) {
this.setState({ isShowCommentsCancelBtn: true });
} else {
this.setState({ isShowCommentsCancelBtn: false });
}
}
=======方法2===========
//直接是箭头函数的调用,把方法包在箭头函数里了
onFocus={() => {
this._commentsTextGetFocus();
}}
//方法实现
_commentsTextGetFocus() {
if (this.state.commentsText.length > 0) {
this.setState({ isShowCommentsCancelBtn: true });
} else {
this.setState({ isShowCommentsCancelBtn: false });
}
第二种,传递匿名函数会导致每一次的props都不相同,让组件出现无谓的渲染,Q友说的。
2.如果未指定父组件的