DjangoBoys DjangoBoys - 1 month ago 8
React JSX Question

What is the difference between componentWillMount and componentDidMount in ReactJS?

I looked at Facebook's documentation at https://facebook.github.io/react/docs/component-specs.html and it mentions how componentWillMount is invoked on the client/server whereas componentDidMount is invoked only on the client. What does componentWillMount do to the server?

Answer

componentWillMount is essentially the constructor. You can set instance properties that don't affect render, pull data from a store synchronously and setState with it, and other simple side effect free code you need to run when setting up your component.

It's rarely needed, and not at all with ES6 classes.