diff --git a/package.json b/package.json
index 6c8eb619..4e56b504 100644
--- a/package.json
+++ b/package.json
@@ -51,8 +51,8 @@
"eslint-config-next": "13.2.4",
"next": "13.2.4",
"prettier": "2.8.7",
- "react": "18.2.0",
- "react-dom": "18.2.0",
+ "react": "^18.3.0-next",
+ "react-dom": "^18.3.0-next",
"typescript": "4.9.5"
},
"packageManager": "yarn@3.5.0"
diff --git a/pages/index.tsx b/pages/index.tsx
index 3bb29a78..8dd1d75a 100644
--- a/pages/index.tsx
+++ b/pages/index.tsx
@@ -1,5 +1,5 @@
import React from 'react';
-import { Heading } from '@chakra-ui/react';
+import { Box, Heading, UnorderedList } from '@chakra-ui/react';
import Head from 'next/head';
import InternalLink from '../components/InternalLink';
@@ -14,7 +14,22 @@ export default function Index() {
What is it?
-
+ This is a demo of React.Suspense in data fetching scenarios.
+
+ Main use case is typically showing a loading spinner.
+
+ Suspense helps to simplify the code structure for handling asynchronously data fetched even when it is
+ done incrementally.
+
+
+ Choose one of these different scenarios:
+
+
+
+ 🆕Experimental, RFC-229{' '}
+ use(await fetch) Fetching all data and use latest support of async data fetching
+ via `const data = use(await fetch)`
+
Old wayAll or nothing: Fetching all
data in a top-level `useEffect()` + props-drilling
@@ -31,7 +46,7 @@ export default function Index() {
Side-by-SideComparison: Show
incrementally loading and wait-for-all
-
+
);
}
diff --git a/pages/next/[userName]/[repoName].tsx b/pages/next/[userName]/[repoName].tsx
new file mode 100644
index 00000000..16e4c80c
--- /dev/null
+++ b/pages/next/[userName]/[repoName].tsx
@@ -0,0 +1,69 @@
+'use client';
+import React, { use, Suspense, cache } from 'react';
+
+import { fetchRepoBranchesWithCommitStatusesAndPullRequests, fetchUser, User } from '../../../restinpeace/github';
+import { UserRepoFromUrlProvider, useUserRepo } from '../../../components/useUserRepoFromRoute';
+import UserRepo from '../../../container/UserRepo';
+import RichErrorBoundary from '../../../components/RichErrorBoundary';
+import InternalLink from '../../../components/InternalLink';
+import { Spinner } from '../../../components/Spinner';
+import { RepoType } from '../../../components/Repo';
+
+function delay(timeout) {
+ return new Promise((resolve) => {
+ setTimeout(resolve, timeout);
+ });
+}
+
+export default function ReactNextDrivenPage() {
+ return (
+
+
+
+ );
+}
+
+function ReactNextWithUrlContext() {
+ const { userName, repoName } = useUserRepo();
+ const userData: Promise = fetchUserPromise(userName);
+ const repoData: Promise = fetchRepoBranches({ userName, repoName });
+ return (
+
+
+ back to repos
+ }>
+
+
+
+
+ );
+}
+
+const fetchUserPromise: (id) => Promise = cache(async (id) => {
+ await delay(2000);
+ return fetchUser(id);
+});
+const fetchRepoBranches: ({ userName, repoName }) => Promise = cache(async ({ userName, repoName }) => {
+ await delay(2000);
+ return fetchRepoBranchesWithCommitStatusesAndPullRequestsProm({ userName, repoName });
+});
+
+interface Props {
+ userData: Promise;
+ repoData: Promise;
+}
+
+function ReactNext({ userData, repoData }: Props) {
+ const user = use(userData);
+ const repo: RepoType = use(repoData);
+
+ return ;
+}
+
+const fetchRepoBranchesWithCommitStatusesAndPullRequestsProm = cache(async ({ userName, repoName }) =>
+ fetchRepoBranchesWithCommitStatusesAndPullRequests({ userName, repoName }).then((branchesWithCommit) => ({
+ name: repoName,
+ owner: { login: userName },
+ branches: branchesWithCommit.branches,
+ }))
+);
diff --git a/pages/next/index.js b/pages/next/index.js
new file mode 100644
index 00000000..385a6885
--- /dev/null
+++ b/pages/next/index.js
@@ -0,0 +1,27 @@
+'use client'; // this directive should be at top of the file, before any imports.
+
+import React from 'react';
+import { Box, Heading, Link } from '@chakra-ui/react';
+
+import InternalLink from '../../components/InternalLink';
+import { LinkList } from '../../components/LinkList';
+
+export default function Shortcuts() {
+ return (
+
+ back to main page
+
+ Experimental, RFC-229
+
+ use(await fetch) Fetching all data and use latest support of async data fetching via
+ `const data = use(await fetch)`
+
+
+ See GH/reactjs/rfcs/pull/229 for mor
+ details
+
+
+
+