Skip to content

Instantly share code, notes, and snippets.

@flavioribeirojr
Created March 31, 2020 23:50
Show Gist options
  • Save flavioribeirojr/85cf288d121be22b4e1672df73d7b740 to your computer and use it in GitHub Desktop.
Save flavioribeirojr/85cf288d121be22b4e1672df73d7b740 to your computer and use it in GitHub Desktop.
Redux Shop Store Access
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