Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
hehecat opened this issue Oct 22, 2019 · 0 comments
Open

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

hehecat opened this issue Oct 22, 2019 · 0 comments

Comments

@hehecat
Copy link

hehecat commented Oct 22, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant