Created
January 7, 2019 23:03
-
-
Save wesleymonaro/b6537f8358e0dae97485661d3cf8b5ca to your computer and use it in GitHub Desktop.
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, { Component } from "react"; | |
import { connect } from "react-redux"; | |
import { compraMateriais } from "./action"; | |
class HomeComponent extends Component { | |
render() { | |
const { materiais, compraMateriais } = this.props; | |
return ( | |
<div> | |
<h1>Teste Redux</h1> | |
<button onClick={() => compraMateriais()}>Comprar material</button> | |
<ul> | |
{materiais.map(material => ( | |
<li key={material.nome}> | |
{material.nome}, {material.qtd} unidades | |
</li> | |
))} | |
</ul> | |
</div> | |
); | |
} | |
} | |
const mapStateToProps = state => ({ | |
materiais: state.reducer.materiais | |
}); | |
const mapDispatchToProps = { | |
compraMateriais | |
}; | |
const Home = connect( | |
mapStateToProps, | |
mapDispatchToProps | |
)(HomeComponent); | |
export default Home; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment