import axios from 'axios'; import React, { useState, useEffect } from 'react'; import { Form, Button, Row, Image, Col, Container } from 'react-bootstrap'; import { isAuthenticated } from '../utils/auth'; import catchErrors from '../utils/catchErrors'; function Chat(props) { const [user, setUser] = useState('') const [error, setError] = useState('') const [disabled, setDisabled] = useState(true) const userId = isAuthenticated() async function getProfile(userId) { try { const response = await axios.get(`/users/${userId}`) setUser(response.data) } catch (error) { catchErrors(error, setError) } } // let defaultname='' let defaultname = sessionStorage.getItem('name'); const [inner, setInner] = useState(['']) const [chat, setChat] = useState([inner]) //object로 key는 보낸사람 value는 메세지 function handleChange(e) { e.preventDefault() setInner(e.target.value) console.log(e.target.value) setDisabled(false) } function sendMsgCH(e) { e.preventDefault() props.setSingleChat(inner) props.sendMsg(e) setInner('') setDisabled(true) console.log(chat) } useEffect(() => { getProfile(userId) }, [userId]) useEffect(() => { setChat([...chat, props.singleChat]) console.log('UseEffect singlechat', chat) // check() }, [props.singleChat]) useEffect(() => { setChat([...chat, props.recievedMsg]) console.log('UseEffect recievechat', chat) }, [props.recievedMsg]) const time = new Date().toLocaleTimeString() return (