-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(react-query): add docs for
<PrefetchInfiniteQuery/>
Co-authored-by: Gwansik Kim <[email protected]> Co-authored-by: Juhyeok Kang <[email protected]>
- Loading branch information
1 parent
cc0b196
commit 8f26227
Showing
8 changed files
with
135 additions
and
73 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
docs/suspensive.org/src/pages/docs/react-query/PrefetchInfiniteQuery.en.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Callout, Sandpack } from '@/components' | ||
|
||
# PrefetchInfiniteQuery | ||
|
||
A component that allows you to use usePrefetchInfiniteQuery in JSX, avoiding the limitations of React hooks. | ||
|
||
```jsx /PrefetchInfiniteQuery/ | ||
import { PrefetchInfiniteQuery, useSuspenseQuery } from '@suspensive/react-query' | ||
import { InView } from '@suspensive/react-dom' | ||
|
||
const PostsPage = () => { | ||
const { data: posts } = useSuspenseQuery({ | ||
queryKey: ['posts'], | ||
queryFn: () => getPosts(), | ||
}) | ||
|
||
return posts.map((post) => ( | ||
<InView> | ||
{({ ref, isInView }) => ( | ||
<> | ||
{isInView ? ( | ||
// 🚫 We can not invoke usePrefetchInfiniteQuery like below because of React Hook rules | ||
// usePrefetchInfiniteQuery({ | ||
// queryKey: ['posts', post.id, 'comments'], | ||
// queryFn: () => getPostComments(post.id), | ||
// }) | ||
|
||
// ✅ We can invoke usePrefetchInfiniteQuery for each post comments query before entering Post Comments page | ||
<PrefetchInfiniteQuery queryKey={['posts', post.id, 'comments']} queryFn={() => getPostComments(post.id)} /> | ||
) : null} | ||
<div ref={ref}> | ||
<h2>{post.title}</h2> | ||
<p>{post.description}</p> | ||
<Link to={`/posts/${post.id}/comments`}>See comments</Link> | ||
</div> | ||
</> | ||
)} | ||
</InView> | ||
)) | ||
} | ||
``` |
41 changes: 41 additions & 0 deletions
41
docs/suspensive.org/src/pages/docs/react-query/PrefetchInfiniteQuery.ko.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Callout, Sandpack } from '@/components' | ||
|
||
# PrefetchInfiniteQuery | ||
|
||
React hook의 제약을 피해 JSX상에서도 usePrefetchInfiniteQuery를 사용할 수 있게 하는 컴포넌트입니다. | ||
|
||
```jsx /PrefetchInfiniteQuery/ | ||
import { PrefetchInfiniteQuery, useSuspenseQuery } from '@suspensive/react-query' | ||
import { InView } from '@suspensive/react-dom' | ||
|
||
const PostsPage = () => { | ||
const { data: posts } = useSuspenseQuery({ | ||
queryKey: ['posts'], | ||
queryFn: () => getPosts(), | ||
}) | ||
|
||
return posts.map((post) => ( | ||
<InView> | ||
{({ ref, isInView }) => ( | ||
<> | ||
{isInView ? ( | ||
// 🚫 React hook의 제약으로 usePrefetchInfiniteQuery를 사용하지 못합니다 | ||
// usePrefetchInfiniteQuery({ | ||
// queryKey: ['posts', post.id, 'comments'], | ||
// queryFn: () => getPostComments(post.id), | ||
// }) | ||
|
||
// ✅ Post Comments 페이지에 들어가기 전에 각각의 post comments query에 대해 usePrefetchInfiniteQuery를 호출할 수 있습니다. | ||
<PrefetchInfiniteQuery queryKey={['posts', post.id, 'comments']} queryFn={() => getPostComments(post.id)} /> | ||
) : null} | ||
<div ref={ref}> | ||
<h2>{post.title}</h2> | ||
<p>{post.description}</p> | ||
<Link to={`/posts/${post.id}/comments`}>See comments</Link> | ||
</div> | ||
</> | ||
)} | ||
</InView> | ||
)) | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters