Skip to Content
Server Actions with .fn()

Server Actions with .fn()

An example of using Vovk.ts Local Procedure Calls (.fn()) inside Next.js Server Actions. The .fn() method calls the controller handler directly on the server without making an HTTP request. When the controller uses contentType: ['multipart/form-data'], .fn() automatically parses FormData.

This example reuses the same FormZodController from the Form with Files example, but calls it via .fn() in a server action instead of the RPC client.

Result








Code

src/app/server-actions/actions.ts
'use server'; import FormZodController from '@/modules/form/FormZodController.js'; export async function submitFormAction(_prevState: unknown, formData: FormData) { try { return { data: await FormZodController.submitForm.fn({ body: formData, params: { id: '5a279068-35d6-4d67-94e0-c21ef4052eea' }, }), }; } catch (e) { return { error: String(e) }; } }

The code above is fetched from GitHub repository. 

Last updated on