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

activeIndex 不受控 #71

Closed
wizard-a opened this issue Aug 16, 2019 · 14 comments
Closed

activeIndex 不受控 #71

wizard-a opened this issue Aug 16, 2019 · 14 comments

Comments

@wizard-a
Copy link

通过Props去更改 activeIndex不受控,如果我更改 images 数据, 相应的 activeIndex 也会更新。

@infeng
Copy link
Owner

infeng commented Aug 16, 2019

感觉反馈,我看下

@wizard-a
Copy link
Author

提 pull request 会快速给合并吗? bug 挺着急的,要不只能自己发 npm 包了

@wizard-a
Copy link
Author

@infeng 建议增加两个属性, defaultActiveIndex 是组件初始化用的index, activeIndex 作为受控属性

@infeng
Copy link
Owner

infeng commented Aug 16, 2019 via email

@wizard-a
Copy link
Author

@infeng #72 已提 PR,看有问题没,没有请 merge

@wizard-a
Copy link
Author

wizard-a commented Aug 16, 2019

@infeng
请看下这个 Demo, https://codesandbox.io/s/laughing-smoke-sxynp 按以下步骤

  1. 点击按钮,打开图片浏览器
  2. 切换下一张图片
  3. 点击更改 index,这时候我把 image 替换成了 4张, 更改 activeIndex 为 2
  4. 结果,通过onChange 改变,activeIndex 变成了 0

@infeng
Copy link
Owner

infeng commented Aug 16, 2019

看到了,我改一下

@wizard-a
Copy link
Author

@infeng 更新了吗?

@infeng
Copy link
Owner

infeng commented Aug 16, 2019

准备了,我测试通过就发布

@infeng
Copy link
Owner

infeng commented Aug 16, 2019

Fixed in v2.10.2

@infeng infeng closed this as completed Aug 16, 2019
@wizard-a
Copy link
Author

image

我看你改了那么多,适配一下 handleChangeImg 方法是不是就好了,其它不用改

@infeng
Copy link
Owner

infeng commented Aug 16, 2019

componentWillReceiveProps 在 React v16.9.0 会出现警告,所以顺便改一下

@wizard-a
Copy link
Author

componentDidUpdate 生命周期里做,会造成多一次渲染吧,渲染完后, 通过改 activeIndex ,还会造成一次渲染吧。 3.0 重构的时候考虑下 getDerivedStateFromProps ?

@infeng
Copy link
Owner

infeng commented Aug 16, 2019

3.0 会改为用 Hooks

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

2 participants