Skip to content

Commit 98dc050

Browse files
authored
docs: fix database guide example to match Server Functions API (#5716)
1 parent bfbe75c commit 98dc050

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

docs/start/framework/react/guide/databases.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,17 @@ import { createServerFn } from '@tanstack/react-start'
2020

2121
const db = createMyDatabaseClient()
2222

23-
export const getUser = createServerFn(async ({ ctx }) => {
24-
const user = await db.getUser(ctx.userId)
23+
export const getUser = createServerFn().handler(async ({ context }) => {
24+
const user = await db.getUser(context.userId)
2525
return user
2626
})
2727

28-
export const createUser = createServerFn(async ({ ctx, input }) => {
29-
const user = await db.createUser(input)
30-
return user
31-
})
28+
export const createUser = createServerFn({ method: 'POST' }).handler(
29+
async ({ data }) => {
30+
const user = await db.createUser(data)
31+
return user
32+
},
33+
)
3234
```
3335

3436
This is obviously contrived, but it demonstrates that you can use literally any database provider with TanStack Start as long as you can call into it from a server function or server route.

0 commit comments

Comments
 (0)