Template
Initial commit
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F22Ms5Cxam5UHyxaCrtZzu
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Adapt a Next.js App Router `searchParams` record (`Record<string, string |
|
||||
* string[] | undefined>`) into a `URLSearchParams` for Hydrogen helpers that
|
||||
* expect a `URLSearchParams` (`getSelectedProductOptions`, `parseCollectionParams`).
|
||||
*
|
||||
* `searchParams` is a `Promise<Record<...>>` in Next 15+ — `await` it first.
|
||||
*/
|
||||
export function toURLSearchParams(
|
||||
input: Record<string, string | string[] | undefined>,
|
||||
): URLSearchParams {
|
||||
const params = new URLSearchParams();
|
||||
for (const [key, value] of Object.entries(input)) {
|
||||
if (Array.isArray(value)) {
|
||||
for (const item of value) params.append(key, item);
|
||||
} else if (value != null) {
|
||||
params.set(key, value);
|
||||
}
|
||||
}
|
||||
return params;
|
||||
}
|
||||
Reference in New Issue
Block a user