Created
February 15, 2019 02:32
-
-
Save bietkul/71fb90248b795e9f8032ac3483360b1f to your computer and use it in GitHub Desktop.
Redux selector to get the total price
This file contains hidden or 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 { createSelector } from 'reselect'; | |
| import get from 'lodash/get'; | |
| const items = state => get(state, 'checkout.items', []); | |
| const calcTotalPrice = ($items = []) => { | |
| let total = 0; | |
| $items.forEach((element) => { | |
| total += get(element, '_source.price') || get(element, 'price'); | |
| }); | |
| return total; | |
| }; | |
| const getTotalPrice = createSelector( | |
| items, | |
| calcTotalPrice, | |
| ); | |
| export { getTotalPrice }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment