Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
students
messenger
Commits
46f894d9
Commit
46f894d9
authored
Jan 13, 2021
by
JeongYeonwoo
Browse files
socket 연결
parent
aded789a
Changes
1
Hide whitespace changes
Inline
Side-by-side
client/src/Components/Chat.js
View file @
46f894d9
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,14 +16,23 @@ function Chat(props) {
...
@@ -13,14 +16,23 @@ 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
"
}}
>
<
Button
variant
=
"
light
"
onClick
=
{
props
.
handleChatc
}
>
{
`<`
}
<
/Button
>
<
Button
variant
=
"
light
"
onClick
=
{
props
.
handleChatc
}
>
{
`<`
}
<
/Button
>
<
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
>
))}
))}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment