Skip to content

Instantly share code, notes, and snippets.

@akmur
Created March 15, 2019 10:25
Show Gist options
  • Save akmur/17a6de0da29e673456e0f6c218c62cb2 to your computer and use it in GitHub Desktop.
Save akmur/17a6de0da29e673456e0f6c218c62cb2 to your computer and use it in GitHub Desktop.
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