react-book-examples icon indicating copy to clipboard operation
react-book-examples copied to clipboard

Tabs 里onChange: () => {},是干什么用的?

Open hehecat opened this issue 5 years ago • 0 comments

1.4.2

  static defaultProps = {
  	classPrefix: 'tabs',
  	onChange: () => {},
  };
.......


3. 用 function prop 与父组件通信

现在我们发现对于 state 来说,它的通信集中在组件内部;对于 props 来说,它的通信是父组 件向子组件的传播。相关代码如下:

7

handleTabClick(activeIndex) { // ...
this.props.onChange({activeIndex, prevIndex});

}

我们通过点击事件 handleTabClick 触发了 onChange prop 回调函数给父组件必要的值。对于兄 弟组件或不相关组件之间的通信,具体请看 2.4 节。

触发回调函数给父组件传值我明白,但是onChange写个空函数是什么意思?传过去啥也不干?

hehecat avatar Oct 22 '19 12:10 hehecat