-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[염성진] Sprint11 #313
The head ref may contain hidden characters: "Next-\uC5FC\uC131\uC9C4-sprint11"
[염성진] Sprint11 #313
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,24 @@ | ||
import Link from "next/link"; | ||
import Image from "next/image"; | ||
import S from "@/components/NavBar.module.css"; | ||
import { useEffect, useState } from "react"; | ||
import { useRouter } from "next/router"; | ||
|
||
function NavBar() { | ||
const [isLoggedIn, setIsLoggedIn] = useState(false); | ||
const [isOpen, setIsOpen] = useState(false); | ||
const router = useRouter(); | ||
const handleLogout = () => { | ||
setIsOpen(!isOpen); | ||
}; | ||
const onClickLogout = () => { | ||
window.localStorage.removeItem("accessToken"); | ||
router.reload(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 요구사항에 로그아웃 후에 페이지가 새로고침 되어야 한다 면 무방하지만
|
||
}; | ||
useEffect(() => { | ||
const token = localStorage.getItem("accessToken"); | ||
setIsLoggedIn(Boolean(token)); | ||
}, []); | ||
return ( | ||
<header className={S.header}> | ||
<div className={S.headerNav}> | ||
|
@@ -32,9 +48,27 @@ function NavBar() { | |
</Link> | ||
</div> | ||
</div> | ||
<Link href="/login" className={S.loginBtn}> | ||
로그인 | ||
</Link> | ||
{isLoggedIn ? ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 중첩된 삼항연산자는 코드를 읽는 흐름이 좋지않게 되어서 렌더 단위를 함수로 만들어서 JSX를 반환하거나 const renderLoggedIn = () => (
<div className={S.userProfileIcon}>
<Image
src="/images/icon/ic_null_user_profile_image.png"
fill
alt="유저 프로필 아이콘"
onClick={handleLogout}
/>
{isOpen && (
<div className={S.dropDown} onClick={onClickLogout}>
로그아웃
</div>
)}
</div>
);
const renderLoggedOut = () => (
<Link href="/login" className={S.loginBtn}>
로그인
</Link>
);
return isLoggedIn ? renderLoggedIn() : renderLoggedOut(); |
||
<div className={S.userProfileIcon}> | ||
<Image | ||
src="/images/icon/ic_null_user_profile_image.png" | ||
fill | ||
alt="유저 프로필 아이콘" | ||
onClick={handleLogout} | ||
/> | ||
{isOpen ? ( | ||
<div className={S.dropDown} onClick={onClickLogout}> | ||
로그아웃 | ||
</div> | ||
) : ( | ||
<></> | ||
)} | ||
</div> | ||
) : ( | ||
<Link href="/login" className={S.loginBtn}> | ||
로그인 | ||
</Link> | ||
)} | ||
</div> | ||
</header> | ||
); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
함수 이름이 handleLogout으로 되어있는데 동작하는 코드는 로그아웃이랑 관련이 없는 코드인것같아요.
logout ui를 열었다 닫는 용도인것같아서 함수 이름을 다른 이름으로 바꿔보는건 어떨까요???
함수가 어떤 동작을 하느냐로 생각해보고 이름지으면 좋습니다 :-)