Last active
July 27, 2017 14:32
-
-
Save sandwichsudo/05501e0a696f3da3516437dde6a38912 to your computer and use it in GitHub Desktop.
Call api when component mounts
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
// src/containers/RepoSearchPage/page/RepoSearchPage.js | |
import React, { Component } from 'react'; | |
import PropTypes from 'prop-types'; | |
import { connect } from 'react-redux'; | |
import { bindActionCreators } from 'redux'; | |
import RepoResultsList from '../components/RepoResultsList/RepoResultsList'; | |
import * as RepoSearchActions from '../actions/RepoSearchActions'; | |
export class RepoSearchPage extends Component { | |
constructor(props) { | |
super(props); | |
} | |
componentWillMount() { | |
this.props.actions.fetchRepos(); | |
} | |
render() { | |
return ( | |
<div> | |
<h1>Top Javascript Repos</h1> | |
<RepoResultsList repos={this.props.searchResults}/> | |
</div> | |
); | |
} | |
} | |
RepoSearchPage.propTypes = { | |
searchResults: PropTypes.array.isRequired, | |
actions: PropTypes.object.isRequired, | |
}; | |
const mapStateToProps = state => ({ | |
searchResults: state.repoSearch.results, | |
}); | |
const mapDispatchToProps = dispatch => ({ | |
actions: bindActionCreators(RepoSearchActions, dispatch), | |
}); | |
export default connect(mapStateToProps, mapDispatchToProps)(RepoSearchPage); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment