#Can anybody please help me with how to display feedback message after submitting form ?

1 messages · Page 1 of 1 (latest)

still ledge
#

So I have a server action function and useFormStatus hook but I can't get it to show the feedback message , here is my code ```js
"use client";
import { useActionState } from "react";
import { useFormStatus } from "react-dom";
export default function OrderSuccess({placeOrder}){
const { pending, data, method, action } = useFormStatus();
console.log(data);

return <div>Success</div>

}```

strong havenBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

floral thunder
#

If you use useActionState wrapping the server action for a form submission, you can retrieve the state sent back by the server to display a message banner. Something like this:

async function serverAction(previousState: unknown, formData: FormData) {
  // ...
  return { success: true }
}

const [formAction, formState, isPending] = useActionState(serverAction, undefined)

return <form action={formAction}>{formState?.success && <div>Success!</div>}</form>