[Solved] How to pass a state to a server action?
Answered
Marble gall posted this in #help-forum
Marble gallOP
Hi
How to pass dateSession to the server action named createSessionAction in the following case :
CreateSessionForm.tsx
---
sessions.tsx
How to pass dateSession to the server action named createSessionAction in the following case :
CreateSessionForm.tsx
import { createSessionAction } from "@/lib/actions/sessions";
function CreateSessionForm({ params }: CreateSessionPageParams) {
const [dateSession, setDateSession] = React.useState<Date>();
return (
<form action={createSessionAction}>---
sessions.tsx
export async function createSessionAction(formData: FormData) {
// How to get dateSession here?Answered by Marble gall
Here is the answer to my question
CreateSessionForm.tsx
---
sessions.tsx
CreateSessionForm.tsx
import { createSessionAction } from "@/lib/actions/sessions";
const createSessionActionWithDateSession = createSessionAction.bind(null, dateSession!)
function CreateSessionForm({ params }: CreateSessionPageParams) {
const [dateSession, setDateSession] = React.useState<Date>();
return (
<form action={createSessionActionWithDateSession }>---
sessions.tsx
export async function createSessionAction(dateSession: Date,formData: FormData) {1 Reply
Marble gallOP
Here is the answer to my question
CreateSessionForm.tsx
---
sessions.tsx
CreateSessionForm.tsx
import { createSessionAction } from "@/lib/actions/sessions";
const createSessionActionWithDateSession = createSessionAction.bind(null, dateSession!)
function CreateSessionForm({ params }: CreateSessionPageParams) {
const [dateSession, setDateSession] = React.useState<Date>();
return (
<form action={createSessionActionWithDateSession }>---
sessions.tsx
export async function createSessionAction(dateSession: Date,formData: FormData) {Answer