In my application, I have a state-dependent component that will be updated after an asynchronous event that is not handled inside the component.
var Status = React.createClass({
getInitialState: function () {
return {
state: 'loading'
};
},
render: function () {
return React.createElement('span', null, this.state.state);
}
});
var status = React.createElement(Status);
React.render(status, mountNode);
I want to be able to do something like this:
doAsyncThing(function callback() {
status.setState({ state: 'done' });
});
I understand that the async logic could be moved to componentDidMount
, as shown here, but is it possible to move it outside the component? Or is it simply the React zen to place such logic inside the component?