Skip to content

Instantly share code, notes, and snippets.

@mohandere
Last active February 19, 2018 11:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mohandere/6c2958e4ae3d3f733b3e692689476d1b to your computer and use it in GitHub Desktop.
Save mohandere/6c2958e4ae3d3f733b3e692689476d1b to your computer and use it in GitHub Desktop.
UserRepos.js - Container component example
// File- src/home/containers/UserRepos.js
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux'
// Import dumb component
import Repo from '../components/Repo';
// Actions
import { doUserRepos } from '../actions/doUserRepos';
// Container component
class UserRepos extends Component {
componentDidMount() {
let username = "mohandere";
this.props.doUserRepos(username);
}
render() {
let { repos } = this.props;
if (this.props.loading) {
return <div className="userReposLoader">Loading...</div>;
}
return (
<div>
<h3>Github Projects</h3>
<ul className="repos">
{repos.map((repo, i) => <Repo key={i} {...repo} />)}
</ul>
</div>
);
}
}
UserRepos.propTypes = {
repos: PropTypes.array
};
const mapStateToProps = state => {
return {
repos: state.home.userRepos.repos,
loading: state.home.userRepos.isLoading
};
};
const mapDispatchToProps = dispatch => {
return bindActionCreators({
doUserRepos
},
dispatch
);
};
export default connect(mapStateToProps, mapDispatchToProps)(UserRepos);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment