-
Notifications
You must be signed in to change notification settings - Fork 7
/
connector.js
34 lines (31 loc) · 1.17 KB
/
connector.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
import { connect } from 'react-redux';
import {
getCurrentBaseProductId,
} from '@shopgate/pwa-common-commerce/product/selectors/product';
import {
getReviewsTotalCount,
getCurrentReviewCount,
getReviewsFetchingState,
} from '@shopgate/pwa-common-commerce/reviews/selectors';
import fetchReviews from '@shopgate/pwa-common-commerce/reviews/actions/fetchReviews';
/**
* Maps the contents of the state to the component props.
* @param {Object} state The current application state.
* @return {Object} The extended component props.
*/
const mapStateToProps = state => ({
currentReviewCount: getCurrentReviewCount(state),
isFetching: getReviewsFetchingState(state),
productId: getCurrentBaseProductId(state),
totalReviewCount: getReviewsTotalCount(state),
});
/**
* Connects the dispatch function to a callable function in the props.
* @param {Function} dispatch The redux dispatch function.
* @return {Object} The extended component props.
*/
const mapDispatchToProps = dispatch => ({
fetchReviews: (productId, limit, offset) =>
dispatch(fetchReviews(productId, limit, offset)),
});
export default connect(mapStateToProps, mapDispatchToProps, null, { withRef: true });