Skip to content

Instantly share code, notes, and snippets.

@fifthsegment
Created September 28, 2017 04:51
Show Gist options
  • Save fifthsegment/dee7528fbc0fc8c0e54d5b2413102e5a to your computer and use it in GitHub Desktop.
Save fifthsegment/dee7528fbc0fc8c0e54d5b2413102e5a to your computer and use it in GitHub Desktop.
import React, { Component } from "react";
import { bindActionCreators } from "redux";
import { connect } from "react-redux";
import { fetchPosts } from "../actions";
import { Card, Button, DescriptionList } from "@shopify/polaris";
class CategoryList extends Component {
createListItems() {
let items = this.props.categories.map(category => ({
term: category.name,
description: (
<Button onClick={() => this.props.fetchPosts(category)}>
Load Posts
</Button>
)
}));
return items;
}
render() {
return (
<Card title="Load Posts from API" sectioned>
<DescriptionList items={this.createListItems()} />
</Card>
);
}
}
function mapStateToProps(state) {
return {
categories: state.categories
// activecategory:state.activecategory
};
}
function matchDispatchToProps(dispatch) {
return bindActionCreators({ fetchPosts: fetchPosts }, dispatch);
}
export default connect(mapStateToProps, matchDispatchToProps)(CategoryList);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment