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

第一章的代码中,[切换tab]的函数有问题。 #45

Open
ZhaoTim opened this issue Dec 4, 2018 · 0 comments
Open

第一章的代码中,[切换tab]的函数有问题。 #45

ZhaoTim opened this issue Dec 4, 2018 · 0 comments

Comments

@ZhaoTim
Copy link

ZhaoTim commented Dec 4, 2018

` handleTabClick(activeIndex) {
const prevIndex = this.state.activeIndex;

if (this.state.activeIndex !== activeIndex &&
    'defaultActiveIndex' in this.props) {
  this.setState({
    activeIndex,
    prevIndex,
  });

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

}`
文中对上面的代码描述是:然后,在 tab 点击事件上,对是否存在 defaultActiveIndex prop 进行判断即可达到在传入 defaultActiveIndex 时使用内部更新,当传入 activeIndex 时使用外部传入的 props 更新。
相关代码如下。

可是仔细看这段代码,只是对传入defaultActiveIndex传入时进行了判断,并没有兼容activeIndex传入时的操作,因为这里面只有一个if判断然后剩下的代码就是if为true时执行的代码,if里面只是判断defaultActiveIndex传入时。

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