Skip to content

Commit 22e58d1

Browse files
committed
docs: isomorphic 동형 관련문서에서 잘못된 코드 수정
1 parent 393bca8 commit 22e58d1

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

contents/posts/React/what-is-isomorphic.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,17 @@ Isomorphic은 "동일한 인터페이스를 유지한 채, 환경에 따라 자
7171
import { useQuery, useSuspenseQuery } from "react-query";
7272

7373
export const useIsomorphicQuery = (suspense: boolean) => {
74-
return suspense ? useSuspenseQuery() : useQuery();
74+
const suspenseQuery = useSuspenseQuery(options);
75+
const query = useQuery(options);
76+
return suspense ? suspenseQuery : query;
7577
};
7678
```
7779

80+
:::details ⚠️ suspense 로 바로 분기처리를 하면 리액트 Hook 의 규칙에 어긋납니다
81+
훅은 컴포넌트의 렌더링 중에 항상 같은 순서로 호출되어야 한다.
82+
즉, 조건문이나 분기 안에서 훅을 호출하면 안 된다.
83+
:::
84+
7885
왜냐하면 `suspense` 라는 플래그를 통해 사용자가 직접 환경을 인식하고 선택해야 하기 때문입니다. <br/>
7986
따라서 이 경우는 Isomorphic 이라는 네이밍을 쓰지 않는 것이 좋습니다.
8087

0 commit comments

Comments
 (0)