Skip to content

Instantly share code, notes, and snippets.

@Tauka
Last active April 16, 2017 00:30
Show Gist options
  • Select an option

  • Save Tauka/ea19e0b41a353ba9fc2eba273aa5e037 to your computer and use it in GitHub Desktop.

Select an option

Save Tauka/ea19e0b41a353ba9fc2eba273aa5e037 to your computer and use it in GitHub Desktop.
import React from "react";
import { connect } from "react-redux";
import { bindActionCreators } from "redux";
import * as actions from "./actions.js";
@connect((store) => {
return {
someStore: store.someStore,
};
},
(dispatch) => {
return {
actions: bindActionCreators(actions, dispatch)
}
})
export default class SomeComponent extends React.Component {
constructor(props) {
super();
this.state = {
success: null,
loading: false
}
}
componentWillMount() {
this.props.actions.typicalAction(() => {this.setState({loading: true})}, () => {this.setState({success: true, loading: false})}, () => {this.setState({success: false, loading: false})});
}
render() {
let condRender = null;
if (this.state.loading) {
condRender = <div> LOADING </div>;
} else if (this.state.success == true) {
condRender = <div> MAIN CONTENT </div>;
} else if (!this.state.success) {
condRender = <div> ERROR </div>;
}
return (
condRender
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment