Next.js Discord

Discord Forum

Server Action on drag-and-drop

Answered
Plott Hound posted this in #help-forum
Open in Discord
Avatar
Plott HoundOP
How can I programmatically trigger a form submission, or similarly, send data to a server, in the onDragEnd event handler of a drag-and-drop interaction in Next? I’m using Next.js 14 and would like to know the best approach to invoke a Server Action when the user completes a drag-and-drop action.
Answered by Plott Hound
solution:
const handleDragEnd = async (event: DragEndEvent) => {
  const res = await serverAction(payload)
}
View full answer

8 Replies

Avatar
Param san
Image
Call a server action function to send data to the server.
@Plott Hound Hope you find the answer helpful.
Avatar
Plott HoundOP
Thanks for replying. I’ll give this a try in the morning and get back to you
Avatar
Param san
Sure 😄
You can DM me
Avatar
Plott HoundOP
I’ve prepared the form data payload and made the server action. I just usually submit forms with <form action.. I’ve not done it with a payload in my function:

const handleDragEnd = (event: DragEndEvent) => {
Avatar
Plott HoundOP
solution:
const handleDragEnd = async (event: DragEndEvent) => {
  const res = await serverAction(payload)
}
Answer