#Server Actions not working for me. Help.

7 messages · Page 1 of 1 (latest)

pallid finch
#

action.ts

'use server'
 
interface contactFormProps
{
    name:string;
    email:string;
    Message:string;

}
export async function sendMail(props:contactFormProps) {

  // ...

  let res = await fetch(
    `http://dummyjson.com/products/1`
  );
  await new Promise((resolve) => setTimeout(resolve, 20));
  //console.log(res.json)
  //return res.json();
  return  JSON.stringify( " success ") ;
}

client

  const onSubmit = async (data:T) => {

    let { response } = await action(data);
    console.log(" output :"+response)
  };

I just want it respond. All i get is output : undefined

fringe skiffBOT
#

🔎 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)

celest void
#

Your action returns the string " success ". Trying to destructure the return value in the client code returns undefined.

pallid finch
#

example?

#

i figured out

#

await is wrong

#

action().then((response:any) => {
console.log(response); // fetched movies
});