Next.js Discord

Discord Forum

Server Actions not working for me. Help.

Unanswered
Spectacled bear posted this in #help-forum
Open in Discord
Spectacled bearOP
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

6 Replies

Giant panda
Your action returns the string " success ". Trying to destructure the return value in the client code returns undefined.
Spectacled bearOP
example?
Spectacled bearOP
i figured out
await is wrong
action().then((response:any) => {
console.log(response); // fetched movies
});
this worked