Skip to content

Instantly share code, notes, and snippets.

@wesleymonaro
Created January 7, 2019 23:03
Show Gist options
  • Save wesleymonaro/b6537f8358e0dae97485661d3cf8b5ca to your computer and use it in GitHub Desktop.
Save wesleymonaro/b6537f8358e0dae97485661d3cf8b5ca to your computer and use it in GitHub Desktop.
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