-
Notifications
You must be signed in to change notification settings - Fork 27.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce useOptimisticPathname and useOptimisticSearchParams
- Loading branch information
Showing
7 changed files
with
235 additions
and
47 deletions.
There are no files selected for viewing
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
5 changes: 5 additions & 0 deletions
5
...2e/app-dir/hooks/app/hooks/use-optimistic-pathname-and-search-params/dynamic/[id]/page.js
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,5 @@ | ||
export default async function Page({ params }) { | ||
const { id } = await params | ||
await new Promise((resolve) => setTimeout(resolve, 1000)) | ||
return <div id={`target-page`}>ID={id}</div> | ||
} |
46 changes: 46 additions & 0 deletions
46
test/e2e/app-dir/hooks/app/hooks/use-optimistic-pathname-and-search-params/layout.js
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,46 @@ | ||
'use client' | ||
|
||
import { | ||
useOptimisticPathname, | ||
useOptimisticSearchParams, | ||
usePathname, | ||
useSearchParams, | ||
} from 'next/navigation' | ||
|
||
import Link from 'next/link' | ||
|
||
export default function Layout({ children }) { | ||
const optimisticPathname = useOptimisticPathname() | ||
const optimisticSearchParams = useOptimisticSearchParams() | ||
const pathname = usePathname() | ||
const searchParams = useSearchParams() | ||
return ( | ||
<> | ||
<p> | ||
optimisticPathname= | ||
<span id="optimistic-pathname">{optimisticPathname}</span> | ||
</p> | ||
<p> | ||
pathname= | ||
<span id="pathname">{pathname}</span> | ||
</p> | ||
<p> | ||
optimisticSearchParams= | ||
<span id="optimistic-search-params"> | ||
{optimisticSearchParams.toString()} | ||
</span> | ||
</p> | ||
<p> | ||
searchParams= | ||
<span id="search-params">{searchParams.toString()}</span> | ||
</p> | ||
<Link | ||
id="navigation-link" | ||
href="/hooks/use-optimistic-pathname-and-search-params/dynamic/1?id=1" | ||
> | ||
Navigate to Dynamic Page | ||
</Link> | ||
<div>{children}</div> | ||
</> | ||
) | ||
} |
3 changes: 3 additions & 0 deletions
3
test/e2e/app-dir/hooks/app/hooks/use-optimistic-pathname-and-search-params/page.js
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,3 @@ | ||
export default function Page() { | ||
return <div>Home</div> | ||
} |
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