Skip to content

Instantly share code, notes, and snippets.

@ahmedmusawir
Created August 18, 2018 10:00
Show Gist options
  • Save ahmedmusawir/7885be074f6f2d5ab9c571d8b1ca703b to your computer and use it in GitHub Desktop.
Save ahmedmusawir/7885be074f6f2d5ab9c571d8b1ca703b to your computer and use it in GitHub Desktop.
REACT - EVEN SHOWS STATE WITHOUT 'THIS' BINDING WITH ARROW FUNCTION
import React, { Component } from 'react';
import PropTypes from 'prop-types';
export class Contact extends Component {
state = {
id: 1,
name: 'Bibo'
};
onShowClick = () => {
console.log(this.state);
};
render() {
let { name, email, phone } = this.props;
return (
<div className="col-sm-6 col-md-6 col-lg-6">
<div className="card card-body mb-3">
<h4>
{name}
<i
className="fa fa-arrow-circle-down float-right"
aria-hidden="true"
onClick={this.onShowClick}
/>
</h4>
<ul className="list-group">
<li className="list-group-item">
<strong className="text-danger">
<i className="fa fa-phone-square" aria-hidden="true" /> Phone:
</strong>{' '}
{email}
</li>
<li className="list-group-item">
<strong className="text-danger">
<i className="fa fa-envelope" aria-hidden="true" /> Email:
</strong>{' '}
{phone}
</li>
</ul>
</div>
</div>
);
}
}
Contact.propTypes = {
name: PropTypes.string.isRequired,
email: PropTypes.string.isRequired,
phone: PropTypes.string.isRequired
};
export default Contact;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment