-
Notifications
You must be signed in to change notification settings - Fork 95
/
Question.js
40 lines (36 loc) · 1.05 KB
/
Question.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import React, { Component } from 'react'
import { connect } from 'react-redux'
import { loadQuestionDetail } from 'actions/questions'
import Helmet from 'react-helmet'
import { browserHistory } from 'react-router'
import PropTypes from 'prop-types'
class Question extends Component {
static fetchData({ store, params, history }) {
let { id } = params
return store.dispatch(loadQuestionDetail({ id, history }))
}
componentDidMount() {
let { id } = this.props.params
this.props.loadQuestionDetail({ id, history: browserHistory })
}
render() {
let { question } = this.props
return (
<div>
<Helmet
title={'Question ' + this.props.params.id}
/>
<h2>{ question.get('content') }</h2>
<h3> User: {question.getIn(['user', 'name'])} </h3>
</div>
)
}
}
function mapStateToProps (state) {
return { question: state.questionDetail }
}
Question.propTypes = {
question: PropTypes.object.isRequired
}
export { Question }
export default connect(mapStateToProps, { loadQuestionDetail })(Question)