OpenList.js 995 Bytes
Newer Older
우지원's avatar
e    
우지원 committed
1
2
import axios from 'axios';
import React, { useEffect, useState } from 'react'
우지원's avatar
ul    
우지원 committed
3
4
import { ListGroup } from 'react-bootstrap';

Soo Hyun Kim's avatar
soo0115    
Soo Hyun Kim committed
5
function OpenList(props) {
우지원's avatar
e    
우지원 committed
6
7
8
9
10
11
12
13
14
15
16
  const [list, setList] = useState([]);

  useEffect(() => {
    getOpenList();
  }, []);

  async function getOpenList() {
    let res = await axios.get('/room/Openlist')
    console.log('가져온거', res)
    setList(res.data)
  }
Soo Hyun Kim's avatar
soo0115    
Soo Hyun Kim committed
17
18

  function enterChatroomCH(e) {
우지원's avatar
e    
우지원 committed
19
20
    console.log(e.target.name)
    console.log(e.target)
Soo Hyun Kim's avatar
soo0115    
Soo Hyun Kim committed
21
22
23
24
25
26
    const roomName = e.target.name
    props.enterChatroom(roomName) // 각각의 room으로 들어가도록 설정해야 함
    props.setRoomName(roomName)
    // props.clearChat()
  }

우지원's avatar
e    
우지원 committed
27
28
  //user.hasOwnProperty('이름');

우지원's avatar
ul    
우지원 committed
29
30
  return (
    <div>
우지원's avatar
e    
우지원 committed
31
      {list.map((item, index) =>
우지원's avatar
ul    
우지원 committed
32
        <ListGroup key={index}>
우지원's avatar
e    
우지원 committed
33
34
          <ListGroup.Item action onClick={enterChatroomCH} name={item.roomName}>
            {item.roomName}
우지원's avatar
ul    
우지원 committed
35
36
37
38
39
40
41
42
          </ListGroup.Item>
        </ListGroup>
      )}
    </div>
  )
}

export default OpenList