react-native-rn-videoplayer icon indicating copy to clipboard operation
react-native-rn-videoplayer copied to clipboard

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

Open wulaizi opened this issue 4 years ago • 2 comments

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

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

wulaizi avatar Dec 14 '20 05:12 wulaizi

说错了不应该是componentDidUpdate

应该是componentWillReceiveProps shouldComponentUpdate 都可以

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

wulaizi avatar Dec 14 '20 06:12 wulaizi

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

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

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

A-ANing avatar Dec 14 '20 06:12 A-ANing