From 5fc36eaa8bd43f60f190baf2daa9d745c3497fe1 Mon Sep 17 00:00:00 2001 From: Lukas Frey Date: Tue, 24 Dec 2024 11:27:25 +0100 Subject: [PATCH 1/3] fix docs for formdata server functions --- docs/framework/react/start/server-functions.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/framework/react/start/server-functions.md b/docs/framework/react/start/server-functions.md index a669a7148b..a099807413 100644 --- a/docs/framework/react/start/server-functions.md +++ b/docs/framework/react/start/server-functions.md @@ -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') @@ -700,7 +700,7 @@ 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) => { const name = formData.get('name') @@ -739,7 +739,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') From fd837a5bc68de66819706899078685a50ca14215 Mon Sep 17 00:00:00 2001 From: Sean Cassiere <33615041+SeanCassiere@users.noreply.github.com> Date: Tue, 14 Jan 2025 10:30:02 +1300 Subject: [PATCH 2/3] Apply suggestions from code review --- docs/framework/react/start/server-functions.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/framework/react/start/server-functions.md b/docs/framework/react/start/server-functions.md index a099807413..741cf16c06 100644 --- a/docs/framework/react/start/server-functions.md +++ b/docs/framework/react/start/server-functions.md @@ -702,6 +702,10 @@ To do this, we can utilize the `url` property of the server function: ```ts const yourFn = createServerFn({ method: 'POST' }) .validator((formData) => { + if (!(formData instanceof FormData)) { + throw new Error('Invalid form data') + } + const name = formData.get('name') if (!name) { From dccb071ca6c528428c114ab68c7eef108b402dde Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Mon, 13 Jan 2025 21:31:04 +0000 Subject: [PATCH 3/3] ci: apply automated fixes --- docs/framework/react/start/server-functions.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/framework/react/start/server-functions.md b/docs/framework/react/start/server-functions.md index 741cf16c06..807a782fea 100644 --- a/docs/framework/react/start/server-functions.md +++ b/docs/framework/react/start/server-functions.md @@ -702,10 +702,10 @@ To do this, we can utilize the `url` property of the server function: ```ts const yourFn = createServerFn({ method: 'POST' }) .validator((formData) => { - if (!(formData instanceof FormData)) { + if (!(formData instanceof FormData)) { throw new Error('Invalid form data') } - + const name = formData.get('name') if (!name) {