Skip to content

Commit bb52adc

Browse files
authored
Fix @/hooks and add suspense so nextjs can handle useSearchParams (#212)
* Fix @/hooks * Fix build for useSearchParams by adding suspense
1 parent 7c7ea3d commit bb52adc

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

components.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
},
1313
"aliases": {
1414
"components": "@/components",
15-
"utils": "@/lib/utils"
15+
"utils": "@/lib/utils",
16+
"hooks": "@/hooks"
1617
}
1718
}

src/app/layout.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { formMetaTags } from "@/lib/utils";
22
import { Providers } from "@/providers/providers";
33
import { Inter } from "next/font/google";
4-
import React from "react";
4+
import React, { Suspense } from "react";
55
import { Toaster } from "sonner";
66
import "./globals.css";
77

@@ -18,20 +18,22 @@ export default function RootLayout({
1818
<body
1919
className={`${inter.className} dark text-foreground bg-background w-full min-h-screen`}
2020
>
21-
<main className="flex flex-col min-h-screen w-full">
22-
<Providers>{children}</Providers>
23-
<Toaster
21+
<Suspense>
22+
<main className="flex flex-col min-h-screen w-full">
23+
<Providers>{children}</Providers>
24+
<Toaster
2425
toastOptions={{
2526
unstyled: false,
2627
classNames: {
2728
toast:
2829
"!bg-slate-500 border-2 !border-slate-900/40 !text-foreground",
2930
error:
30-
"!bg-destructive !border-destructive/40 !text-foreground",
31-
},
32-
}}
33-
/>
34-
</main>
31+
"!bg-destructive !border-destructive/40 !text-foreground",
32+
},
33+
}}
34+
/>
35+
</main>
36+
</Suspense>
3537
</body>
3638
</html>
3739
);

src/hooks/useWallet.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { useWallet as useWalletAdapter } from "@solana/wallet-adapter-react";
2+
import { PublicKey } from "@solana/web3.js";
3+
import { useSearchParams } from "next/navigation";
4+
5+
export const useWallet = () => {
6+
const searchParams = useSearchParams();
7+
const { publicKey, ...rest } = useWalletAdapter();
8+
return {
9+
publicKey: searchParams.get("viewAs")
10+
? new PublicKey(searchParams.get("viewAs") as string)
11+
: publicKey,
12+
...rest,
13+
};
14+
};

0 commit comments

Comments
 (0)