server action callback?
Answered
North Pacific hake posted this in #help-forum
North Pacific hakeOP
Hi there I can't seem to find anything on this topic, or at least clearly enough explained to where I understand 😅.
Basically, when I use a server action with the function this:
Can I somehow throw up a toast notification that the action was a success or there was an error? I am aware of
Basically, when I use a server action with the function this:
"use server";
export const test = async (data) => {
console.log(data);
};Can I somehow throw up a toast notification that the action was a success or there was an error? I am aware of
useFormStatus however that seems to only have a boolean that could just be used to see if it was submitted.Answered by Ray
I took your function for example, since your action there didn't return anything
12 Replies
@North Pacific hake Hi there I can't seem to find anything on this topic, or at least clearly enough explained to where I understand 😅.
Basically, when I use a server action with the function this:
"use server";
export const test = async (data) => {
console.log(data);
};
Can I somehow throw up a toast notification that the action was a success or there was an error? I am aware of `useFormStatus` however that seems to only have a boolean that could just be used to see if it was submitted.
you can use like this
<form action={async (data) => {
await test(data)
toast.success("success")
}}>
</form>the form need to be client component
@Ray you can use like this
ts
<form action={async (data) => {
await test(data)
toast.success("success")
}}>
</form>
North Pacific hakeOP
there is no way to return data from the server to client with server action?
@North Pacific hake there is no way to return data from the server to client with server action?
I took your function for example, since your action there didn't return anything
Answer
you can return value from the server action
but the value need to be serializable
North Pacific hakeOP
i expected a return when i didnt return anything...
my bad lol
and overthought it
thanks again Ray
np 😀