import axios from 'axios'; import React, { useState, useEffect } from 'react'; import { Navbar, Nav, Button } from 'react-bootstrap'; import { handleLogout, isAuthenticated } from '../utils/auth'; const INIT_USER = { username: '' } function Menu() { const user = isAuthenticated() const [userName, setUsername] = useState(INIT_USER) async function getLoginedUser() { const userId = localStorage.getItem('user') const response = await axios.get(`/users/${userId}`) console.log(response.data.username) const resName = response.data.username // const resName = JSON.stringify(response.data.username) // console.log(resName) setUsername(resName) } console.log(userName) useEffect((user) => { if (localStorage.getItem('user')) { getLoginedUser(user) } }, []) return ( YDK Messenger {user ? <>
{userName} 님 환영합니다
: }
) } export default Menu