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

Soo Hyun Kim's avatar
soo0115    
Soo Hyun Kim committed
5
function OpenList(props) {
6
7
8
9
10
11
12
13
14
15
16
17
  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
18
19
20
21
22
23
24
25

  function enterChatroomCH(e) {
    const roomName = e.target.name
    props.enterChatroom(roomName) // 각각의 room으로 들어가도록 설정해야 함
    props.setRoomName(roomName)
    // props.clearChat()
  }

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

export default OpenList