Created
March 15, 2019 10:25
-
-
Save akmur/17a6de0da29e673456e0f6c218c62cb2 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, { Component } from 'react' | |
import { loadUser } from './redux/actions/index.actions' | |
// this is what matters for redux | |
import { connect } from 'react-redux' | |
class User extends Component { | |
componentDidMount() { | |
if (!this.props.user.isLoaded) { | |
this.props.loadUser() | |
} | |
} | |
render() { | |
if (this.props.user.isLoaded) { | |
return ( | |
<div> | |
<h1>{this.props.user.data.name}</h1> | |
<div>{this.props.user.data.email}</div> | |
</div> | |
) | |
} else { | |
return <div>Loading</div> | |
} | |
} | |
} | |
// this is redux stuff | |
const mapStateToProps = state => { | |
return { | |
user: state.userReducer | |
} | |
} | |
// and then you export the component | |
// passing through redux | |
export default connect( | |
mapStateToProps, | |
{ loadUser } | |
)(User) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment