Last active
December 11, 2015 05:11
-
-
Save gblache/e8c870890e4c7e303fd6 to your computer and use it in GitHub Desktop.
This file contains 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 fetch from './actions' | |
import { connect } from 'react-redux' | |
const MyComponent extends React.Component { | |
componentDidMount() { | |
const { dispatch } = this.props | |
dispatch(fetch()) | |
} | |
render() { | |
const { requestState: { isLoading, response } } = this.props | |
if (isLoading) return (<p>I'm loading!</p>) | |
return ( | |
<p>Response: {response}</p> | |
) | |
} | |
} | |
const mapStateToProps = (state) => { | |
const { requestState } = state | |
return { requestState } | |
} | |
export default connect(mapStateToProps)(MyComponent) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment