I looked at Facebook's documentation at (React.Component) 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?
The componentWillMount lifecycle hook is an ideal choice when it comes to updating business logic, app configuration updates, and API calls. The componentWillMount() lifecycle hook is primarily used to implement server-side logic before the actual rendering happens, such as making an API call to the server.
ReactJS – componentWillMount() Method This function is generally called before the component gets loaded in the DOM tree. This method is called before the render() method is called, so it can be used to initialize the state but the constructor is preferred. This method is generally used in server-side rendering.
The componentDidUpdate()is called after componentDidMount() and can be useful to perform some action when the state of the component changes. Parameters: Following are the parameter used in this function: prevProps: Previous props passed to the component. prevState: Previous state of the component.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With