Skip to content

Instantly share code, notes, and snippets.

@mmahalwy
Last active May 31, 2018 06:33
Show Gist options
  • Save mmahalwy/3a93011bdaa6d76480b33ad2f0a99c0c to your computer and use it in GitHub Desktop.
Save mmahalwy/3a93011bdaa6d76480b33ad2f0a99c0c to your computer and use it in GitHub Desktop.
Slim containers
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