Created
March 31, 2020 23:50
-
-
Save flavioribeirojr/85cf288d121be22b4e1672df73d7b740 to your computer and use it in GitHub Desktop.
Redux Shop Store Access
This file contains 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 React from 'react'; | |
import { connect } from 'react-redux'; | |
function ProductList({ cart }) { // A prop cart foi injetada pelo HOC do React Redux | |
return ( | |
<div> | |
{ | |
cart | |
.map(cartProduct => ( | |
<h1 key={cartProduct.id}> | |
{ cartProduct.name } | |
</h1> | |
)) | |
} | |
</div> | |
); | |
} | |
const mapStateToProps = state => ({ | |
cart: state.shop.cart // Aqui selecionamos o cart que está dentro da store do redux | |
}); | |
export default connect(mapStateToProps)(ProductList); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment