Server action not receiving any data?
Answered
Transvaal lion posted this in #help-forum
Transvaal lionOP
"use client";
import { create } from "zustand";
import { useState } from "react";
import { createTask } from "@/helpers/actions";
export default function NewTask() {
const [duration, setDuration] = useState(10);
const [name, setName] = useState("");
const [description, setDescription] = useState("");
return (
<div className="bg-white rounded-lg p-5 m-5">
<form className="flex flex-col gap-4" action={createTask}>
<input
type="text"
className="p-5 border-2 border-solid border-gray-200"
placeholder="New task's name."
value={name}
onChange={(e) => {
setName(e.target.value);
}}
/>
<input
type="text"
className="p-5 border-2 border-solid border-gray-200"
placeholder="New task's description."
value={description}
onChange={(e) => {
setDescription(e.target.value);
}}
/>
<input
type="range"
className="w-full mt-5 border-2 border-solid border-gray-200"
placeholder="New task's duration."
value={duration}
min={5}
max={120}
id="duration"
onChange={(e) => {
setDuration(e.target.valueAsNumber);
}}
/>
<span>{duration} minutes.</span>
<button className="p-5 bg-blue-600 rounded-lg text-white" type="submit">
Create task
</button>
</form>
</div>
);
}"use server"
export async function createTask(e: FormData) {
const body = Object.fromEntries(e)
console.log("🚀 ~ file: actions.ts:5 ~ createTask ~ body:", body)
console.log(JSON.stringify({e}))
}Hey, why does this action not recieve any data?
2 Replies
Transvaal lionOP
Found the issue.
Transvaal lionOP
Ever input needs a
name prop to get passed.Answer