|
1 |
| -import React from 'react'; |
2 |
| -import {bindActionCreators} from 'redux'; |
3 |
| -import {Compare, ProductList} from '../../components'; |
4 |
| -import * as productActions from '../../actions'; |
5 |
| -import {connect} from 'react-redux'; |
| 1 | +import React, {Component} from 'react' |
| 2 | +import {bindActionCreators} from 'redux' |
| 3 | +import {Compare, ProductList} from '../../components' |
| 4 | +import * as productActions from '../../actions/product' |
| 5 | +import {connect} from 'react-redux' |
6 | 6 |
|
7 |
| -class Home extends React.Component { |
| 7 | +class Home extends Component { |
8 | 8 | componentWillMount() {
|
9 |
| - this.props.actions.getProducts(); |
| 9 | + this.props.actions.getProducts() |
10 | 10 | }
|
11 | 11 |
|
12 | 12 | render() {
|
13 |
| - const {products, actions} = this.props; |
14 |
| - const compareProducts = products.filter(product => product.compare); |
| 13 | + const {products, actions} = this.props |
| 14 | + const compareProducts = products.filter(product => product.compare) |
15 | 15 |
|
16 | 16 | return (
|
17 |
| - <div className="Home mt-5"> |
| 17 | + <div className="home mt-5"> |
18 | 18 | <ProductList products={products} compare={actions.compare}/>
|
19 |
| - {compareProducts.length >= 2 ? <Compare products={compareProducts}/> : null} |
| 19 | + {compareProducts.length >= 2 && |
| 20 | + <Compare products={compareProducts}/> |
| 21 | + } |
20 | 22 | </div>
|
21 |
| - ); |
| 23 | + ) |
22 | 24 | }
|
23 | 25 | }
|
24 | 26 |
|
25 |
| -function mapStateToProps(state) { |
26 |
| - return { |
| 27 | +export default connect( |
| 28 | + state => ({ |
27 | 29 | products: state.product.products
|
28 |
| - } |
29 |
| -} |
30 |
| - |
31 |
| -function mapDispatchToProps(dispatch) { |
32 |
| - return { |
| 30 | + }), |
| 31 | + dispatch => ({ |
33 | 32 | actions: bindActionCreators(productActions, dispatch)
|
34 |
| - }; |
35 |
| -} |
36 |
| - |
37 |
| -export default connect( |
38 |
| - mapStateToProps, |
39 |
| - mapDispatchToProps |
40 |
| -)(Home); |
| 33 | + }) |
| 34 | +)(Home) |
0 commit comments