diff --git a/docs/suspensive.org/src/pages/docs/react-query/PrefetchQuery.en.mdx b/docs/suspensive.org/src/pages/docs/react-query/PrefetchQuery.en.mdx new file mode 100644 index 000000000..60738ea77 --- /dev/null +++ b/docs/suspensive.org/src/pages/docs/react-query/PrefetchQuery.en.mdx @@ -0,0 +1,52 @@ +import { Callout, Sandpack } from '@/components' + +# PrefetchQuery + +A component that allows you to use usePrefetchQuery in JSX, avoiding the limitations of React hooks. + +```jsx /PrefetchQuery/ +import { PrefetchQuery, useSuspenseQuery, queryOptions } from '@suspensive/react-query' +import { InView } from '@suspensive/react-dom' +import { useQuery } from '@tanstack/react-query' + +const PostsPage = () => { + const { data: posts } = useSuspenseQuery(query.posts()) + + return posts.map(({ id, title, description }) => ( + + {({ ref, isInView }) => { + return ( + <> + {isInView ? ( + // 🚫 We can not invoke usePrefetchQuery like below because of React Hook rules + // usePrefetchQuery(query.post(post.id)) + + // ✅ We can invoke usePrefetch for each post query before entering Post page + + ) : null} + +
+

{title}

+

{description}

+
+ + + ) + }} +
+ )) +} + +const query = { + posts: () => + queryOptions({ + queryKey: ['posts'], + queryFn: () => getPosts(), + }), + post: (postId) => + queryOptions({ + queryKey: ['posts', postId], + queryFn: () => getPost(postId), + }), +} +``` diff --git a/docs/suspensive.org/src/pages/docs/react-query/PrefetchQuery.ko.mdx b/docs/suspensive.org/src/pages/docs/react-query/PrefetchQuery.ko.mdx new file mode 100644 index 000000000..849d287da --- /dev/null +++ b/docs/suspensive.org/src/pages/docs/react-query/PrefetchQuery.ko.mdx @@ -0,0 +1,52 @@ +import { Callout, Sandpack } from '@/components' + +# PrefetchQuery + +React hook의 제약을 피해 JSX상에서도 usePrefetchQuery를 사용할 수 있게 하는 컴포넌트입니다. + +```jsx /PrefetchQuery/ +import { PrefetchQuery, useSuspenseQuery, queryOptions } from '@suspensive/react-query' +import { InView } from '@suspensive/react-dom' +import { useQuery } from '@tanstack/react-query' + +const PostsPage = () => { + const { data: posts } = useSuspenseQuery(query.posts()) + + return posts.map(({ id, title, description }) => ( + + {({ ref, isInView }) => { + return ( + <> + {isInView ? ( + // 🚫 React hook의 제약으로 usePrefetchQuery를 사용하지 못합니다 + // usePrefetchQuery(query.post(post.id)) + + // ✅ Post 페이지에 들어가기 전에 각각의 post query에 대해 usePrefetch를 호출할 수 있습니다. + + ) : null} + +
+

{title}

+

{description}

+
+ + + ) + }} +
+ )) +} + +const query = { + posts: () => + queryOptions({ + queryKey: ['posts'], + queryFn: () => getPosts(), + }), + post: (postId) => + queryOptions({ + queryKey: ['posts', postId], + queryFn: () => getPost(postId), + }), +} +``` diff --git a/docs/suspensive.org/src/pages/docs/react-query/_meta.en.json b/docs/suspensive.org/src/pages/docs/react-query/_meta.en.json index 0e655f096..3481d528c 100644 --- a/docs/suspensive.org/src/pages/docs/react-query/_meta.en.json +++ b/docs/suspensive.org/src/pages/docs/react-query/_meta.en.json @@ -16,5 +16,6 @@ "SuspenseQuery": { "title": "" }, "SuspenseQueries": { "title": "" }, "SuspenseInfiniteQuery": { "title": "" }, + "PrefetchQuery": { "title": "" }, "QueryErrorBoundary": { "title": "" } } diff --git a/docs/suspensive.org/src/pages/docs/react-query/_meta.ko.json b/docs/suspensive.org/src/pages/docs/react-query/_meta.ko.json index a62f5c82b..8306f0a00 100644 --- a/docs/suspensive.org/src/pages/docs/react-query/_meta.ko.json +++ b/docs/suspensive.org/src/pages/docs/react-query/_meta.ko.json @@ -16,5 +16,6 @@ "SuspenseQuery": { "title": "" }, "SuspenseQueries": { "title": "" }, "SuspenseInfiniteQuery": { "title": "" }, + "PrefetchQuery": { "title": "" }, "QueryErrorBoundary": { "title": "" } }