3 ms·
Yeah, if you dispatch in a constructor and the effect is synchronous, it's going to setState somewhere and React will complain, whereas if you do it from compon
by steve_taylor 9y ago
Yeah, if you dispatch in a constructor and the effect is synchronous, it's going to setState somewhere and React will complain, whereas if you do it from componentWillMount, maybe React won't complain, but I'm not sure. My understanding is that componentWillMount was needed for React.createClass, but not so much ES6 classes. It seems a bit weird to be calling setState on a component within the context of another component being created. As far as I'm concerned, setState should only ever be called from an event handler, such as user input, an endpoint returning a response, or a timer event.
- AnkhMorporkian 9y agoI'm not sure how familiar with it you are, but that's kinda a result of flux/redux architecture. There's a global state that things are passed props to. If there is some change triggered as the result of a component being mounted, say a globalish "there's now a tooltip active", that may modify components including the component that triggered the change. That's probably a simplistic example, but it really does happen.