Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(start): fix FormData server functions examples #3062

Merged
merged 4 commits into from
Jan 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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')
SeanCassiere marked this conversation as resolved.
Show resolved Hide resolved

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
Loading