Format data when using server actions
Answered
Hunting wasp posted this in #help-forum
Hunting waspOP
Hello there!
So, I'm having a little bit of trouble, I am using server actions to send a form. The problem is, a part of this data is inside an array contained in a useState property. How can I send this extra info to the server action method?
To be more clear, this is the code:
A possible alternative is to insert the data as a hidden input in the form, but I want to keep the original structure, also it's a less clean solution.
excuse me if it's a dumb question, still a noob,
thanks for your help!
So, I'm having a little bit of trouble, I am using server actions to send a form. The problem is, a part of this data is inside an array contained in a useState property. How can I send this extra info to the server action method?
To be more clear, this is the code:
const [notes, setNotes] = useState<Note[]>([]);
<form action={insertClient}>
<Base show={stepperStatus === 0} />
<button type="submit">Insert</button>
</form>A possible alternative is to insert the data as a hidden input in the form, but I want to keep the original structure, also it's a less clean solution.
excuse me if it's a dumb question, still a noob,
thanks for your help!
3 Replies
<form action={insertClient.bind(null, notes)}>Answer
then your insertClient will receive notes as first argument
async function insertClient(notes: Note[], formData: FormData) {}Hunting waspOP
I found it now in the documentation, will read it better next time, can't believe it just slipped me! Anyways, thank you very much for your help! @Ray