forked from benmvp/react-workshop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EmailListItem.js
38 lines (32 loc) · 937 Bytes
/
EmailListItem.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import React from 'react';
import {EMAIL_PROP_TYPE} from './constants';
export default class EmailListItem extends React.Component {
static propTypes = {
email: EMAIL_PROP_TYPE.isRequired,
onDelete: React.PropTypes.func.isRequired,
onSelect: React.PropTypes.func
}
_handleClick(e) {
let {email, onSelect} = this.props;
if (onSelect) {
e.stopPropagation();
onSelect(email.id);
}
}
_handleDelete(e) {
e.stopPropagation();
this.props.onDelete(this.props.email.id);
}
render() {
let {
email: {from, subject}
} = this.props;
return (
<div onClick={this._handleClick.bind(this)}>
<span>{from}</span>
<span>{subject}</span>
<button onClick={this._handleDelete.bind(this)}>Delete</button>
</div>
);
}
}