Chat.js 1.58 KB
Newer Older
JeongYeonwoo's avatar
JeongYeonwoo committed
1
import React, { useEffect, useState } from 'react';
2
import { Form, Button, Row } from 'react-bootstrap';
우지원's avatar
ul    
우지원 committed
3
4
5


function Chat(props) {
6
  // const [username, setUsername] = useState('')
Choi Ga Young's avatar
aa    
Choi Ga Young committed
7
8
9
  let defaultname = sessionStorage.getItem('name');
  // const [newName, setNewName] = useState({ username: '' });
  // const [state, setState] = useState(false);
JeongYeonwoo's avatar
JeongYeonwoo committed
10

11
12
13
14
15
16
17
18
19
20
  function handleChange(e) {
    e.preventDefault()
    props.setInner(e.target.value)
    console.log(e.target.value)
  }

  function sendMsgCH(e) {
    props.sendMsg(e)
  }

Choi Ga Young's avatar
aa    
Choi Ga Young committed
21
22
23
24
  // const saveChange = (e) => {
  //   const { name, value } = e.target
  //   setNewName({ ...newName, [name]: value })
  // }
25

Choi Ga Young's avatar
aa    
Choi Ga Young committed
26
27
28
  // const handleSubmit = (e) => {
  //   e.preventDefault()
  //   setState(true)
29
  // }
Choi Ga Young's avatar
aa    
Choi Ga Young committed
30

우지원's avatar
ul    
우지원 committed
31
  return (
JeongYeonwoo's avatar
JeongYeonwoo committed
32

우지원's avatar
ul    
우지원 committed
33
34
    <div className="chat" id="chat" style={{ border: "2px solid", height: "300%", margin: "1%", borderColor: "#BDBDBD" }}>
      <Button variant="light" onClick={props.handleChatc} >{`<`}</Button>
Choi Ga Young's avatar
aa    
Choi Ga Young committed
35
36
37
38
39
40

      <Form onSubmit={handleSubmit}>
        <Form.Control name='newname' type='text' onChange={saveChange} />
        <Button variant="primary" type="submit">전송</Button>
      </Form>

41
42
43
      <h2>현재 {props.roomName} 입니다.</h2>
      {      props.chatmsg.map((value, index) => (
        <Row key={index} className='ml-3'>
Choi Ga Young's avatar
aa    
Choi Ga Young committed
44
          {props.roomName}에서 {defaultname}님이 보낸 메세지 : {value}
45
46
47
48
49
50
51
        </Row>
      ))}

      <Form onSubmit={sendMsgCH}>
        <Form.Control name='msg' type='text' onChange={handleChange} />
        <Button variant="primary" type="submit">전송</Button>
      </Form>
우지원's avatar
ul    
우지원 committed
52
53
54
55
56
57
58
    </div>


  );
}

export default Chat;