DEV Community

componentWillMount() vs componentDidMount()

Tori Crawford on May 07, 2019

While building my React and Redux project in bootcamp, I had a difficult time understanding the fundamental differences between the componentWillMo...
Collapse
 
aks30498 profile image
aks30498

I don't understand this part: componentWillMount() which is called twice, once to the server and once on the client. It is called after the initial render when the client received data from the server and before the data is displayed in the browser.

I've read this reason at a number of places, but I don't understand what server are you talking about ?

Also am using hooks now but isn't it so that even with componentDidMount/useEffect with empty dependency array, I already have the component rendered once ? I mean, I set the state such that values are undefined initially and then I show a loader or something.

So what's the difference when you say that when componentWillUpdate has made an API call, component has already rendered once before the response comes back and state is set ? can't I set the initial state such that I get a blank view until componentWillUpdate's fetch call brings me data ?

Collapse
 
thisurathenuka profile image
Thisura Thenuka

Wow! I was so confused. Thanks a lot for your help. Love from Sri Lanka

Collapse
 
yoann_buzenet profile image
Yoann Buzenet

Thank you for your help !! Greetings from Paris !