Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- springboot
- vitejs
- Test
- fetch
- sveltekit
- EUREKA
- svelte
- ubuntu
- vuex
- fastapi
- Java
- NextJS13
- Vue
- style
- InteliJ
- react
- Shell
- Python
- d3js
- Logging
- nodejs
- NextJS
- npm
- post
- gradle
- 오라클
- loguru
- JUnit
- Spring
- Vue3
Archives
- Today
- Total
양군의 행복한 이야기
useSession호출시 무한 렌더링 본문
NextJs13에서 NextAuth사용시 클라이언트 컴포넌트에서 useSession을 사용하여 Console.log를 찍으며 무한으로 렌더링이 된다.
예시
"use client";
import { useSession } from "next-auth/react";
const ClientSession = async (props) => {
let session = useSession();
console.log(session);
return (
<div>
<div>클라이언트 세션</div>
</div>
);
};
export default ClientSession;
위의 코드는 session을 무한으로 로그를 남기게 된다...
원인은 잘 모르겠다 ㅡㅡ;;
해결 방법은 컴포넌트를 다른 방식으로 만들면된다.
"use client";
import { useSession } from "next-auth/react";
export default function page(props) {
let session = useSession();
console.log(session, new Date());
return <div>클라이언트 세션</div>;
}
이리 하면.. 딱 한번만 로그를 남기고 끝난다.