Skip to content

Commit

Permalink
fix: Followings에서 Suspense 제거 #100
Browse files Browse the repository at this point in the history
다음과 같은 문제가 있음
- `Suspense` 부모 컴포넌트도 렌더링 블록되는 문제
- 같은 레벨의 `Followers`에서 `useQuery`에 `suspense: true` 옵션 주면 다음과 같은 에러 발생

```
Uncaught Error: A component suspended while responding to synchronous input
```
  • Loading branch information
leegwae committed Nov 23, 2022
1 parent 79cd301 commit 1aee9bb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
12 changes: 5 additions & 7 deletions client/src/hooks/useFollowingsQuery.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import {
getFollowings,
GetFollowingsResponse,
GetFollowingsResult,
} from '@apis/user';
import type { GetFollowingsResponse, GetFollowingsResult } from '@apis/user';

import { getFollowings } from '@apis/user';
import { useQuery } from '@tanstack/react-query';

import queryKeyCreator from '@/queryKeyCreator';

type FollowingQueryData = {
type FollowingsQueryData = {
statusCode: number;
} & GetFollowingsResult;

Expand All @@ -19,7 +17,7 @@ const useFollowingsQuery = (
const query = useQuery<
GetFollowingsResponse,
unknown,
FollowingQueryData,
FollowingsQueryData,
[string]
>(key, getFollowings, {
...options,
Expand Down
28 changes: 13 additions & 15 deletions client/src/layouts/Followings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ import SearchInput from '@components/searchInput';
import UserList from '@components/UserList';
import useDebouncedValue from '@hooks/useDebouncedValue';
import useFollowingsQuery from '@hooks/useFollowingsQuery';
import React, { useState, Suspense } from 'react';
import React, { useState } from 'react';

const Followings = () => {
const DEBOUNCE_DELAY = 500;
const [filter, setFilter] = useState('');
const debouncedFilter = useDebouncedValue(filter, DEBOUNCE_DELAY);
const followingsQuery = useFollowingsQuery(debouncedFilter, {
suspense: true,
});
const followingsQuery = useFollowingsQuery(debouncedFilter);

return (
<div>
Expand All @@ -22,17 +20,17 @@ const Followings = () => {
placeholder="검색하기"
/>
</div>
<Suspense fallback={<div>loading...</div>}>
{followingsQuery.data?.followings.length ? (
<UserList>
{followingsQuery.data.followings.map((user) => (
<FollowingUserItem key={user._id} user={user} />
))}
</UserList>
) : (
'일치하는 사용자가 없습니다.'
)}
</Suspense>
{followingsQuery.isLoading ? (
<div>loading...</div>
) : followingsQuery.data?.followings.length ? (
<UserList>
{followingsQuery.data.followings.map((user) => (
<FollowingUserItem key={user._id} user={user} />
))}
</UserList>
) : (
'일치하는 사용자가 없습니다.'
)}
</div>
);
};
Expand Down

0 comments on commit 1aee9bb

Please sign in to comment.