Why componentWillMount should not be used?

前端 未结 5 782
傲寒
傲寒 2020-12-14 16:07

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

And why it is better to use componentDidMount.

5条回答
  •  不思量自难忘°
    2020-12-14 16:54

    UPDATE: componentWillMount will soon be deprecated.


    To cite @Dan Abramov

    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.

    Read more here.

提交回复
热议问题