Commit 46f894d9 authored by JeongYeonwoo's avatar JeongYeonwoo
Browse files

socket 연결

parent aded789a
import React from 'react'; import React, { useEffect, useState } from 'react';
import { Form, Button, Row } from 'react-bootstrap'; import { Form, Button, Row } from 'react-bootstrap';
import axios from "axios";
function Chat(props) { function Chat(props) {
const [username, setUsername] = useState('')
function handleChange(e) { function handleChange(e) {
e.preventDefault() e.preventDefault()
props.setInner(e.target.value) props.setInner(e.target.value)
...@@ -13,6 +16,15 @@ function Chat(props) { ...@@ -13,6 +16,15 @@ function Chat(props) {
props.sendMsg(e) props.sendMsg(e)
} }
async function getLoginedUser() { //email로 db에서 찾아오기 ㅇㅇㅇㅇㅇ
const userid = localStorage.getItem('user')
const response = await axios.post(`/users/${userid}`, { 'email': userid })
setUsername(response.data.username)
}
useEffect(() => {
getLoginedUser()
console.log('Chat에서 useEffect', username)
})
return ( return (
<div className="chat" id="chat" style={{ border: "2px solid", height: "300%", margin: "1%", borderColor: "#BDBDBD" }}> <div className="chat" id="chat" style={{ border: "2px solid", height: "300%", margin: "1%", borderColor: "#BDBDBD" }}>
...@@ -20,7 +32,7 @@ function Chat(props) { ...@@ -20,7 +32,7 @@ function Chat(props) {
<h2>현재 {props.roomName} 입니다.</h2> <h2>현재 {props.roomName} 입니다.</h2>
{ props.chatmsg.map((value, index) => ( { props.chatmsg.map((value, index) => (
<Row key={index} className='ml-3'> <Row key={index} className='ml-3'>
{props.roomName}에서 보낸 메세지 : {value} {props.roomName}에서 {username}님이 보낸 메세지 : {value}
</Row> </Row>
))} ))}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment