#ActuallyAutistic web dev. Does front of the front-end. Loves perf and minimalism. Prefers HTML, CSS, Web Standards over JS, UX over DX. Hates div disease.
From developer standpoint I'd add that componentWillMount is roughly the equivalent of just doing stuff in constructor. The difference between using these is very small. I guess componentWillMount only existed because of historical React.createClass reasons when you didn't yet have a constructor in React classes - and once constructor became available with ES6 it pretty much removed any need to having componentWillMount.
The way I think this is that constructor is the place where you put together the initial internal state of your component. This will be the same state for both server rendered and initial browser render. Once browser kicks in then you have all the other lifecycle methods to live with from componentDidMount all the way to componentWillUnmount - all of which are not available when rendering server stuff.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
From developer standpoint I'd add that
componentWillMount
is roughly the equivalent of just doing stuff inconstructor
. The difference between using these is very small. I guesscomponentWillMount
only existed because of historicalReact.createClass
reasons when you didn't yet have aconstructor
in React classes - and onceconstructor
became available with ES6 it pretty much removed any need to havingcomponentWillMount
.The way I think this is that
constructor
is the place where you put together the initial internal state of your component. This will be the same state for both server rendered and initial browser render. Once browser kicks in then you have all the other lifecycle methods to live with fromcomponentDidMount
all the way tocomponentWillUnmount
- all of which are not available when rendering server stuff.