Skip to content

Commit 881f899

Browse files
mfbzbriandoyle81
authored andcommitted
Added nextjs example
1 parent 5d009ed commit 881f899

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

docs/build/tools/react-sdk/index.mdx

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,49 @@ export default Root;
5353
```
5454

5555
:::tip Next.js Users
56-
Place the `FlowProvider` inside your `layout.tsx`. Since React hooks must run on the client, you may need to wrap the provider in a separate file that begins with `'use client'` to avoid issues with server-side rendering.
56+
Create a client component wrapper for the `FlowProvider`:
57+
58+
```tsx title="components/FlowProviderWrapper.tsx"
59+
'use client';
60+
61+
import { FlowProvider } from '@onflow/react-sdk';
62+
import flowJSON from '../flow.json';
63+
64+
export default function FlowProviderWrapper({ children }) {
65+
return (
66+
<FlowProvider
67+
config={{
68+
accessNodeUrl: 'https://access-mainnet.onflow.org',
69+
flowNetwork: 'mainnet',
70+
appDetailTitle: 'My On Chain App',
71+
appDetailIcon: 'https://example.com/icon.png',
72+
appDetailDescription: 'A decentralized app on Flow',
73+
appDetailUrl: 'https://myonchainapp.com',
74+
}}
75+
flowJson={flowJSON}
76+
>
77+
{children}
78+
</FlowProvider>
79+
);
80+
}
81+
```
82+
83+
Then use it in your `layout.tsx`:
84+
85+
```tsx title="app/layout.tsx"
86+
import FlowProviderWrapper from '@/components/FlowProviderWrapper';
87+
88+
export default function RootLayout({ children }) {
89+
return (
90+
<html>
91+
<body>
92+
<FlowProviderWrapper>{children}</FlowProviderWrapper>
93+
</body>
94+
</html>
95+
);
96+
}
97+
```
98+
5799
:::
58100

59101
### 3. Start Building

0 commit comments

Comments
 (0)