Skip to content

Instantly share code, notes, and snippets.

@gblache
Last active December 11, 2015 05:11
Show Gist options
  • Save gblache/e8c870890e4c7e303fd6 to your computer and use it in GitHub Desktop.
Save gblache/e8c870890e4c7e303fd6 to your computer and use it in GitHub Desktop.
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