Last active
April 16, 2017 00:30
-
-
Save Tauka/ea19e0b41a353ba9fc2eba273aa5e037 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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