Skip to content

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

Description

@ZhaoTim

` 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传入时。

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