Skip to content

Instantly share code, notes, and snippets.

@panvourtsis
Created June 9, 2017 18:15
Show Gist options
  • Save panvourtsis/ff67cfbddc3be2f7033f7d4a9db255dc to your computer and use it in GitHub Desktop.
Save panvourtsis/ff67cfbddc3be2f7033f7d4a9db255dc to your computer and use it in GitHub Desktop.
high order component
import { connect } from "react-redux";
import React, { Component } from "react";
import PropTypes from "prop-types";
// Import Components
import RatingList from "./components/RatingList/RatingList";
// Import Actions
import { fetchRatings } from "./RatingsActions";
// import Reducer
import { getRatings } from "./RatingsReducer";
class RatingsPage extends Component {
debugger;
render() {
return (
<div>
<RatingList ratings={this.props.ratings} />
</div>
);
}
}
// Retrieve data from store as props
const mapStateToProps = (state) => {
return {
ratings: getRatings(state)
}
};
const mapDispatchToProps = (dispatch) => {
return {
dispatch,
fetchRatings: dispatch(fetchRatings()),
};
}
RatingsPage.propTypes = {
ratings: PropTypes.arrayOf(PropTypes.object),
dispatch: PropTypes.func.isRequired,
};
export default connect(mapStateToProps, mapDispatchToProps)(RatingsPage);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment