-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApp.js
61 lines (49 loc) · 1.62 KB
/
App.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import React, { Component } from 'react';
import './App.css';
import SingleComment from './singleComment';
class App extends Component {
constructor() {
super();
this.state = {
count: 0,
comments: [],
currentComment: ""
};
}
onInputChange = e => {
this.setState({ currentComment: e.target.value });
}
onClick = () => {
let commentsCopy = this.state.comments.slice();
commentsCopy.push(this.state.currentComment);
this.setState({ comments: commentsCopy, currentComment: "" });
}
deleteComment = i => {
let commentsCopy = this.state.comments.slice();
commentsCopy.splice(i, 1);
this.setState({ comments: commentsCopy })
}
increment = () => {
this.setState({count: this.state.count + 1});
}
render() {
let listedComments = this.state.comments.map((e, i) => {
return (
<SingleComment key={i} comment={e} delete={() => this.deleteComment(i)}/>
);
});
return (
<div>
<input placeholder="Enter a comment" value={this.state.currentComment}
onChange={this.onInputChange} />
<button onClick={this.onClick}>COMMENT</button>
<br />
{ this.state.comments.length === 0 ? "No Comments Yet!" : <ul>{listedComments}</ul>}
<br /><br />
<button onClick={this.increment}>Add As Many Likes As You Want!</button>
{this.state.count}
</div>
);
}
}
export default App;