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
demo 11 里面的 this.isMounted 的作用是什么? #43
Comments
谢谢指出,这个判断确实是多余的。我把它删掉。 |
并不一定吧~ isMounted是在回调函数中,并且涉及网络请求,没人能保证它执行的时候仍旧是Mounted的 |
@Nbsaw 没记错的话,应该是执行get网络请求后才调用的回调函数,如果网比较差,这就会有一个时间差了啊,如果期间被unmount了,也是可能的 |
理论上,获取到数据的时候,组件是可能被卸载的。但是,这个例子里,确实是多余的判断。 另外, |
@ruanyf 我把整个issure都看了下,基本就是react的开发者嫌isMounted不够优雅,想废除它,但又没在react内部给一个完美的代替方案,所以另一个react的贡献者就不同意了。然后就是提出各种workaround,然而所有workaround都不是react自带的,全部仅仅是workaround~ 没看到这个issure的岂不是要被坑? |
阮老师你好。我想请教下这一段里面的this.isMounted的作用。
react-demos/demo11/index.html
Lines 20 to 30 in 15a5be3
看README的描述
componentDidMount
这个钩子调用的时候this.isMounted
应该总是为true
吧。那么这个判断是不是多余的。The text was updated successfully, but these errors were encountered: