-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented MVP for reading URL query params as strings in the root c…
…omponent (#428)
- Loading branch information
1 parent
ace51a0
commit 2576206
Showing
18 changed files
with
135 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { QueryParams } from '@bos-web-engine/common'; | ||
import { useSearchParams } from 'next/navigation'; | ||
import { useEffect, useState } from 'react'; | ||
|
||
export function useQueryParams() { | ||
const searchParams = useSearchParams(); | ||
const [queryParams, setQueryParams] = useState<QueryParams>({}); | ||
|
||
useEffect(() => { | ||
/* | ||
This pattern gives us a more stable reference for queryParams to reduce | ||
re-renders. We only update our state when searchParams changes. | ||
*/ | ||
|
||
const params: QueryParams = {}; | ||
|
||
searchParams.forEach((value, key) => { | ||
params[key] = value; | ||
}); | ||
|
||
setQueryParams(params); | ||
}, [searchParams]); | ||
|
||
return { | ||
queryParams, | ||
}; | ||
} |
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 |
---|---|---|
@@ -1,11 +1,17 @@ | ||
import { Sandbox } from '@bos-web-engine/sandbox'; | ||
|
||
import { useQueryParams } from '@/hooks/useQueryParams'; | ||
import s from '@/styles/home.module.css'; | ||
|
||
export default function Home() { | ||
const { queryParams } = useQueryParams(); | ||
|
||
return ( | ||
<div className={s.wrapper}> | ||
<Sandbox height="calc(100vh - var(--gateway-header-height))" /> | ||
<Sandbox | ||
height="calc(100vh - var(--gateway-header-height))" | ||
queryParams={queryParams} | ||
/> | ||
</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
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,27 @@ | ||
import { QueryParams } from '@bos-web-engine/common'; | ||
import { useSearchParams } from 'next/navigation'; | ||
import { useEffect, useState } from 'react'; | ||
|
||
export function useQueryParams() { | ||
const searchParams = useSearchParams(); | ||
const [queryParams, setQueryParams] = useState<QueryParams>({}); | ||
|
||
useEffect(() => { | ||
/* | ||
This pattern gives us a more stable reference for queryParams to reduce | ||
re-renders. We only update our state when searchParams changes. | ||
*/ | ||
|
||
const params: QueryParams = {}; | ||
|
||
searchParams.forEach((value, key) => { | ||
params[key] = value; | ||
}); | ||
|
||
setQueryParams(params); | ||
}, [searchParams]); | ||
|
||
return { | ||
queryParams, | ||
}; | ||
} |
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
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
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 @@ | ||
export type QueryParams = Record<string, string | undefined>; |
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
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
Oops, something went wrong.