-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChat.js
53 lines (49 loc) · 1.29 KB
/
Chat.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
import TextField from '@material-ui/core/TextField';
export default function Chat({ chat, onMessageSubmit, onTextChange, state }) {
const throttle = (callback, delay) => {
let previousCall = new Date().getTime();
return function () {
const time = new Date().getTime();
console.log('실행되니 ????');
if (time - previousCall >= delay) {
previousCall = time;
callback();
}
};
};
const handleKeyPress = (e) => {
if (e.key === 'Enter') {
onMessageSubmit(e);
}
};
return (
<div className="card">
<div className="render-chat">
<h1>Chat Log</h1>
{chat.map(({ name, message }, index) => {
return (
<div key={index}>
<h3>
{name}: <span>{message}</span>
</h3>
</div>
);
})}
</div>
<form onSubmit={onMessageSubmit}>
{/* <input type="text"></input> */}
<div className="msgBtn">
<input
onKeyPress={handleKeyPress}
name="message"
onChange={(e) => onTextChange(e)}
value={state.message}
id="outlined-multiline-static"
variant="outlined"
label="Message"
/>
</div>
</form>
</div>
);
}