Skip to content

Commit 8261402

Browse files
committed
waku community adapter
1 parent 39d6f4a commit 8261402

File tree

1 file changed

+74
-0
lines changed
  • packages/docs/content/docs/community-adapters

1 file changed

+74
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
---
2+
title: Waku
3+
description: Integrate nuqs with Waku
4+
---
5+
6+
[Waku](https://waku.gg/) is supported as a community-contributed adapter.
7+
8+
## Step 1: Add the adapter code
9+
10+
<Callout type="warn">
11+
The custom adapters APIs are not yet stable and may change in the future
12+
in a minor or patch release (not following SemVer).
13+
</Callout>
14+
15+
```tsx title="app/nuqs-waku-adapter.tsx"
16+
'use client';
17+
18+
import {
19+
type unstable_AdapterOptions as AdapterOptions,
20+
unstable_createAdapterProvider as createAdapterProvider,
21+
renderQueryString,
22+
} from "nuqs/adapters/custom";
23+
import { useRouter_UNSTABLE as useRouter } from "waku";
24+
25+
function useNuqsAdapter() {
26+
const { query, push, replace } = useRouter();
27+
const searchParams = new URLSearchParams(query);
28+
const updateUrl = (search: URLSearchParams, options: AdapterOptions) => {
29+
if (options.history === "push") {
30+
push(renderQueryString(search));
31+
} else {
32+
replace(renderQueryString(search));
33+
}
34+
};
35+
return {
36+
searchParams,
37+
updateUrl,
38+
};
39+
}
40+
41+
export const NuqsAdapter = createAdapterProvider(useNuqsAdapter);
42+
43+
```
44+
45+
## Step 2: wrap your root layout
46+
47+
Integrate the adapter into a _layout.tsx or _root.tsx file, by wrapping the `{children}`
48+
component:
49+
50+
```tsx title="app/_layout.tsx" /NuqsAdapter/
51+
import { Suspense, type ReactNode } from 'react';
52+
53+
import { NuqsAdapter } from './nuqs-waku-adapter'
54+
55+
type LayoutProps = { children: ReactNode };
56+
57+
export default async function Layout({ children }: LayoutProps) {
58+
return (
59+
<>
60+
<NuqsAdapter>
61+
<Suspense>
62+
{children}
63+
</Suspense>
64+
</NuqsAdapter>
65+
</>
66+
);
67+
}
68+
69+
export const getConfig = async () => {
70+
return {
71+
render: 'static',
72+
} as const;
73+
};
74+
```

0 commit comments

Comments
 (0)