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

发现个致命问题,这串代码在render里执行 #19

Open
wulaizi opened this issue Dec 14, 2020 · 2 comments
Open

发现个致命问题,这串代码在render里执行 #19

wulaizi opened this issue Dec 14, 2020 · 2 comments

Comments

@wulaizi
Copy link

wulaizi commented Dec 14, 2020

if (this.url && this.url != this.props.url) { this.onchangeUrl() }
切换视频时报错,最后排查得到onchangeUrl 这个方法里面带有this.setState
而onchangeUrl 的调用位置却是在render处 这样会到导致死循环

大佬要判断地址是否和上一次的一样 可以在生命周期componentDidUpdate 里完成哦

@wulaizi
Copy link
Author

wulaizi commented Dec 14, 2020

说错了不应该是componentDidUpdate

应该是componentWillReceiveProps shouldComponentUpdate 都可以

componentWillReceiveProps(nextProps) {
if (nextProps.url !== this.props.url) {
this.onchangeUrl()
}
}

@A-ANing
Copy link
Owner

A-ANing commented Dec 14, 2020

应该是不会死循环的,因为this.url和props的url不相同才会执行onchangeUrl方法;

当然最好的写法是在com生命周期里;

可以pr一波,我没有时间,最近项目太忙了;

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