Skip to content

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

Description

@hehecat

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写个空函数是什么意思?传过去啥也不干?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions