Created
September 28, 2017 04:51
-
-
Save fifthsegment/dee7528fbc0fc8c0e54d5b2413102e5a to your computer and use it in GitHub Desktop.
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
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