I am using React-Redux to build an application.
To load initial data for a React smart component, I need to dispatch a Redux action where the server data requests will happen.
I've tried dispatching the action in constructor (ES6 implementation), componentWillMount
, and componenetDidMount
. They all worked.
My question is:
is there a recommended place in the React smart component that the action should be dispatched.
The recommended way is, I believe, to do it in componentDidMount. See this for more info.
Edit: Dan Abramov recently stated
In
componentDidMount
Read here.
Documentation is really scarce on "why in
componentDidMount
". I believecomponentWillMount
is not called if you use server-side render, so this could be a reason whycomponentDidMount
is preferred.