-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlike_button.js
More file actions
33 lines (28 loc) · 763 Bytes
/
Copy pathlike_button.js
File metadata and controls
33 lines (28 loc) · 763 Bytes
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
'use strict';
const e = React.createElement;
class LikeButton extends React.Component {
constructor(props) {
super(props);
this.state = { liked: false };
}
render() {
if (this.state.liked) {
return 'You liked comment number: ' + this.props.commentID;
}
return e(
'button',
{ onClick: () => this.setState({ liked: true }) },
'Like'
);
}
}
// Find all DOM containers, and render like buttons into them.
document.querySelectorAll('#like_button_container').forEach(
domContainer => {
// Read the comment ID from a data-* attribute
const commentID = parseInt(domContainer.dataset.commentid, 10);
ReactDOM.render(
e(LikeButton, { commentID: commentID }),
domContainer
);
});