Skip to content

Instantly share code, notes, and snippets.

@kettanaito
Created May 22, 2018 07:53
Show Gist options
  • Save kettanaito/52cc53db7ee81001ccae97de0e02f39c to your computer and use it in GitHub Desktop.
Save kettanaito/52cc53db7ee81001ccae97de0e02f39c to your computer and use it in GitHub Desktop.
Redux - Selector
import React from 'react'
import { connect } from 'react-redux'
import { getTotalPrice } from './cart/selectors'
class Cart extends React.Component {
render() {
const { items, totalPrice } = this.props
return (
<div>
<h3>Items</h3>
{this.renderItems(items)}
<p>Total price: {totalPrice}.</p>
</div>
)
}
}
export default connect(state => ({
items: state.getIn(['cart', 'items']),
totalPrice: getTotalPrice(state.get('cart'))
})(Cart)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment