Skip to content

Commit

Permalink
docs(start): fix FormData server functions examples (#3062)
Browse files Browse the repository at this point in the history
Co-authored-by: Sean Cassiere <[email protected]>
  • Loading branch information
kasulio and SeanCassiere authored Jan 13, 2025
1 parent 9bdaf1c commit a7fece1
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions docs/framework/react/start/server-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ Server functions can accept `FormData` objects as parameters
```tsx
import { createServerFn } from '@tanstack/start'

export const greetUser = createServerFn()
export const greetUser = createServerFn({ method: 'POST' })
.validator((data) => {
if (!(data instanceof FormData)) {
throw new Error('Invalid form data')
Expand Down Expand Up @@ -701,8 +701,12 @@ to send the form data to the server function.
To do this, we can utilize the `url` property of the server function:

```ts
const yourFn = createServerFn()
const yourFn = createServerFn({ method: 'POST' })
.validator((formData) => {
if (!(formData instanceof FormData)) {
throw new Error('Invalid form data')
}

const name = formData.get('name')

if (!name) {
Expand Down Expand Up @@ -740,7 +744,7 @@ to attach the argument to the [`FormData`](https://developer.mozilla.org/en-US/d
server function:

```tsx
const yourFn = createServerFn()
const yourFn = createServerFn({ method: 'POST' })
.validator((formData) => {
if (!(formData instanceof FormData)) {
throw new Error('Invalid form data')
Expand Down

0 comments on commit a7fece1

Please sign in to comment.