Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React, { Component, Fragment } from "react";
- import { connect } from "react-redux";
- import PropTypes from "prop-types";
- import { getLeads, deleteLead } from "../../actions/leads";
- class Leads extends Component {
- static propTypes = {
- leads: PropTypes.array.isRequired
- };
- componentDidMount() {
- this.props.getLeads();
- }
- render() {
- return (
- <Fragment>
- <h2>Leads</h2>
- <table className="table table-striped">
- <thead>
- <tr>
- <th>ID</th>
- <th>Namne</th>
- <th>Email</th>
- <th>Message</th>
- <th />
- </tr>
- </thead>
- <tbody>
- {this.props.leads.map(lead => (
- <tr key="{lead.id}">
- <td>{lead.id}</td>
- <td>{lead.name}</td>
- <td>{lead.email}</td>
- <td>{lead.message}</td>
- <td>
- <button
- onClick={this.props.deleteLead.bind(this, lead.id)}
- className="btn btn-danger btn-asset"
- >
- Delete
- </button>
- </td>
- </tr>
- ))}
- </tbody>
- </table>
- </Fragment>
- );
- }
- }
- const mapStateToProps = state => ({
- leads: state.leads.leads
- });
- export default connect(
- mapStateToProps,
- { getLeads }
- )(Leads);
Advertisement
Add Comment
Please, Sign In to add comment