stream-saga/src/js/components/Posts.jsx

39 lines
780 B
React
Raw Normal View History

2019-06-19 17:08:53 -04:00
import React, { Component } from "react"
import { connect } from "react-redux"
import { getData } from "../actions/index"
export class Post extends Component {
componentDidMount() {
this.props.getData()
}
render() {
2019-06-21 00:59:25 -04:00
let cand = this.props.candidate === undefined ? 'Not set' : this.props.candidate
2019-06-19 17:08:53 -04:00
return (
2019-06-21 00:59:25 -04:00
<div>
<p>Candidate: {cand}</p>
<ul className="list-group list-group-flush">
2019-06-19 17:08:53 -04:00
{this.props.articles.map(el => (
2019-06-21 00:59:25 -04:00
<li className="list-group-item" key={el.id}>
<p>{el.title}</p>
2019-06-19 17:08:53 -04:00
</li>
))}
2019-06-21 00:59:25 -04:00
</ul>
</div>
2019-06-19 17:08:53 -04:00
)
}
}
function mapStateToProps(state) {
return {
2019-06-21 00:59:25 -04:00
articles: state.remoteArticles.slice(0, 10),
candidate: state.candidate
2019-06-19 17:08:53 -04:00
}
}
export default connect(
mapStateToProps,
{ getData }
)(Post)