Why should not the WillMount component be used?

Failure to call server to retrieve data in componentWillMount lifecycle method - bad practice?

And why is it better to use componentDidMount.

+21
source share
5 answers

To bring @ Dan Abramov

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

More details here .

+17
source

- /2018
, .
v16.3.2 "" :

  • componentWillMount
  • componentWillReceiveProps
  • componentWillUpdate

.


, componentWillMount ( class es6). constructor.
.
componentDidMount , componentDidMount .

?
, constructor/componentWillMount render render, , , render , , " " ?.
, , componentWillMount, render. , , , render .
, - render ( null <div/>), , .

+17

componentDidMount - :

  • componentDidMount , . , undefined, .

  • , componentWillMount ( ), , , , . componentDidMount , . , componentWillMount.

+5

, , .

componentWillMount, , , "", . . (, API Promises), render , ( Redux -).

componentDidMount, , , - ( mount). , , , ( "" ) .

+2

  • ()
  • componentWillMount()/UNSAFE_componentWillMount() ( 16)
  • ()
  • componentDidMount()

Constructor componentWillMount render(), .

, api componentDidMount - .

ComponentWillMount ES6, . ComponentWillMount , 17.

In addition to the above, the response switched to a fiber response architecture in order to avoid unnecessary re-rendering and increased productivity; the response decided to abandon the componentWillMount, componentWillReciveProps and componentWillUpdate methods.

+1
source

All Articles