Last active
May 31, 2018 06:33
-
-
Save mmahalwy/3a93011bdaa6d76480b33ad2f0a99c0c to your computer and use it in GitHub Desktop.
Slim containers
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 PropTypes from 'prop-types'; | |
import { connect } from 'react-redux'; | |
import { follow } from '../actions/follow'; | |
import { fetchUser } from '../actions/users'; | |
import Navbar from '../components/Navbar'; | |
import Profile from '../components/Profile'; | |
function mapStateToProps(state, { match: { params } }) { | |
return { | |
profile: state.users.entities[params.userId] | |
}; | |
} | |
class ProfileContainer extends React.Component { | |
componentDidMount () { | |
const { fetchUser, match: { params } } = this.props; | |
fetchUser(params.userId); | |
} | |
handleFollow = () => { | |
const { follow, match: { params } } = this.props; | |
follow(params.userId); | |
}; | |
render() { | |
return ( | |
<div> | |
<Navbar /> | |
<Profile profile={profile} onFollowPress={this.handleFollow} /> | |
</div> | |
); | |
} | |
} | |
export default connect(mapStateToProps, { follow, fetchUser })(ProfileContainer); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment