Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: added tests for supporting app client hooks in pages
- Loading branch information
Showing
5 changed files
with
86 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { useRouter } from 'next/router' | ||
import { usePathname, useSearchParams } from 'next/navigation' | ||
import { useState } from 'react' | ||
import { useEffect } from 'react' | ||
|
||
export const RouterHooksFixtures = () => { | ||
const router = useRouter() | ||
const searchParams = useSearchParams() | ||
const pathname = usePathname() | ||
|
||
const [value, setValue] = useState(null) | ||
useEffect(() => { | ||
if (!router.isReady) { | ||
return | ||
} | ||
|
||
setValue(searchParams.get('key')) | ||
}, [router.isReady, searchParams]) | ||
|
||
return ( | ||
<div id={router.isReady ? 'router-ready' : 'router-not-ready'}> | ||
<div id="key-value">{value}</div> | ||
<div id="pathname">{pathname}</div> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { RouterHooksFixtures } from '../../components/router-hooks-fixtures' | ||
|
||
export default function Page() { | ||
return <RouterHooksFixtures /> | ||
} |
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,13 @@ | ||
import { RouterHooksFixtures } from '../../../components/router-hooks-fixtures' | ||
|
||
export default function Page() { | ||
return <RouterHooksFixtures /> | ||
} | ||
|
||
export const getStaticProps = () => { | ||
return { props: {} } | ||
} | ||
|
||
export const getStaticPaths = () => { | ||
return { fallback: 'blocking', paths: [{ params: { id: '1' } }] } | ||
} |
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,9 @@ | ||
import { RouterHooksFixtures } from '../../components/router-hooks-fixtures' | ||
|
||
export default function Page() { | ||
return <RouterHooksFixtures /> | ||
} | ||
|
||
export const getStaticProps = () => { | ||
return { props: {} } | ||
} |
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