为什么不应该使用 componentWillMount? [英] Why componentWillMount should not be used?

查看:50
本文介绍了为什么不应该使用 componentWillMount?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 componentWillMount 生命周期方法中触发服务器调用以获取数据是一种不好的做法吗?

Firing server call to fetch data in componentWillMount life cycle method a bad practice?

为什么最好使用 componentDidMount.

And why it is better to use componentDidMount.

推荐答案

更新: componentWillMount 即将已弃用.

UPDATE: componentWillMount will soon be deprecated.

引用@Dan Abramov

React 的未来版本中,我们预计在某些情况下 componentWillMount 会触发多次,因此您应该使用 componentDidMount 来处理网络请求.

In future versions of React we expect that componentWillMount will fire more than once in some cases, so you should use componentDidMount for network requests.

此处阅读更多信息.

这篇关于为什么不应该使用 componentWillMount?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆