2 ms·
I used them mostly for server side rendering, if I remeber correctly. componentDidMount will fire only on the client and componentWillMount on client and serve
by k__ 9y ago
I used them mostly for server side rendering, if I remeber correctly.
componentDidMount will fire only on the client and componentWillMount on client and server.
Since the server rendered stuff wasn't interactive I could only do a subset of the things the client allowed, so I would do these in componentWillMount and the rest in componentDidMount only on the client.
- danabramov 9y agoIf there’s some specific use case we’re missing in the blog post please let us know! `componentWillMount` is technically equivalent to the constructor so there's nothing you could do on the server you couldn't do in the constructor instead. https://reactjs.org/blog/2018/03/27/update-on-async-rendering.html#other-scenarios https://reactjs.org/blog/2018/03/27/update-on-async-renderin...
- k__ 9y agoI know, but I often avoid meddling with constructors. Passing the right stuff to super etc.