-
[nextjs] Cannot update a component(``) while rendering a different component(``) 에러NextJS 2023. 6. 6. 21:17

if (!session) { router.push("/login"); }클라이언트 컴포넌트에서 세션이 없을 때 /login 페이지로 이동하는 중 에러가 발생
해결방법
1. useEffect 사용
const router = useRouter(); useEffect(() => { if (!session) { router.push("/login"); } }, [router, session]);2. 서버 컴포넌트로 변경 후 redirect 사용
import { redirect } from "next/navigation"; if (!session) { redirect("/login"); }'NextJS' 카테고리의 다른 글
[Nextjs] fromdata 데이터 가져오기 / cause: Error: Multipart: Boundary not found (0) 2023.05.17 [Next.js] Its return type 'Promise<Element>' is not a valid JSX element. 에 (0) 2023.04.14 NextJS 13버전 설치 (0) 2023.03.26