generated from chiffre-io/template-library
-
-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use `useInsertionEffect` to subscribe to navigation events rather than `useEffect`, which can happen too late. Add demo that cycles between various types of components to test. See #343 (comment)
- Loading branch information
Showing
10 changed files
with
119 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { parseAsInteger, parseAsString } from '../../../../../dist/parsers' | ||
|
||
export const counterParser = parseAsInteger.withDefault(0) | ||
export const fromParser = parseAsString |
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,33 @@ | ||
'use client' | ||
|
||
import Link from 'next/link' | ||
import { useQueryState } from '../../../../../dist' | ||
import { counterParser, fromParser } from './parsers' | ||
|
||
type RoutingTourViewProps = { | ||
thisPage: string | ||
nextPage: string | ||
} | ||
|
||
export const RoutingTourView: React.FC<RoutingTourViewProps> = ({ | ||
thisPage, | ||
nextPage | ||
}) => { | ||
const [counter] = useQueryState('counter', counterParser) | ||
const [from] = useQueryState('from', fromParser) | ||
return ( | ||
<> | ||
<Link | ||
href={`/app/routing-tour/${nextPage}?from=${thisPage}&counter=${ | ||
counter + 1 | ||
}`} | ||
> | ||
Next | ||
</Link> | ||
<p>Came from: {from}</p> | ||
<p>This page: {thisPage}</p> | ||
<p>Next page: {nextPage}</p> | ||
<p>Counter: {counter}</p> | ||
</> | ||
) | ||
} |
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,10 @@ | ||
import { Suspense } from 'react' | ||
import { RoutingTourView } from '../_components/view' | ||
|
||
export default function PageA() { | ||
return ( | ||
<Suspense> | ||
<RoutingTourView thisPage="a" nextPage="b" /> | ||
</Suspense> | ||
) | ||
} |
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,10 @@ | ||
import { Suspense } from 'react' | ||
import { RoutingTourView } from '../_components/view' | ||
|
||
export default function PageB() { | ||
return ( | ||
<Suspense> | ||
<RoutingTourView thisPage="b" nextPage="c" /> | ||
</Suspense> | ||
) | ||
} |
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,7 @@ | ||
'use client' | ||
|
||
import { RoutingTourView } from '../_components/view' | ||
|
||
export default function PageC() { | ||
return <RoutingTourView thisPage="c" nextPage="d" /> | ||
} |
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,7 @@ | ||
'use client' | ||
|
||
import { RoutingTourView } from '../_components/view' | ||
|
||
export default function PageD() { | ||
return <RoutingTourView thisPage="d" nextPage="a" /> | ||
} |
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,22 @@ | ||
'use client' | ||
|
||
import Link from 'next/link' | ||
|
||
export default function ServerStartPage() { | ||
return ( | ||
<ul> | ||
<li> | ||
<Link href="/app/routing-tour/a?from=start.client">a (server)</Link> | ||
</li> | ||
<li> | ||
<Link href="/app/routing-tour/b?from=start.client">b (server)</Link> | ||
</li> | ||
<li> | ||
<Link href="/app/routing-tour/c?from=start.client">c (client)</Link> | ||
</li> | ||
<li> | ||
<Link href="/app/routing-tour/d?from=start.client">d (client)</Link> | ||
</li> | ||
</ul> | ||
) | ||
} |
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,20 @@ | ||
import Link from 'next/link' | ||
|
||
export default function ServerStartPage() { | ||
return ( | ||
<ul> | ||
<li> | ||
<Link href="/app/routing-tour/a?from=start.client">a (server)</Link> | ||
</li> | ||
<li> | ||
<Link href="/app/routing-tour/b?from=start.client">b (server)</Link> | ||
</li> | ||
<li> | ||
<Link href="/app/routing-tour/c?from=start.client">c (client)</Link> | ||
</li> | ||
<li> | ||
<Link href="/app/routing-tour/d?from=start.client">d (client)</Link> | ||
</li> | ||
</ul> | ||
) | ||
} |
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