Next.js Discord

Discord Forum

async error in client component

Answered
American black bear posted this in #help-forum
Open in Discord
Avatar
American black bearOP
hello, im having a page component with async for data fetch, im importing a shadcn form component which is client on it, im not using async in the form component but it gives me the error

Error: async/await is not yet supported in Client Components, only Server Components. This error is often caused by accidentally adding 'use client' to a module that was originally written for the server.

im passing the fetched data from the page component to the form component

Form : https://gist.github.com/Enkai0110/f4207241bb01bb65675e36cc5c9e988c
page : https://gist.github.com/Enkai0110/5309d0b3c6f812236c384173a3a0dd06
Answered by Ray
it will become client component when it get imported to another client component
View full answer

9 Replies

Avatar
could you show the code on @/components/heading?
Avatar
American black bearOP
oh, just relized im using an uneccesary async in there, but im not wrapping it with "use client" why would error happen

interface headingProps {
  title: string;
  description: string;
}

const Heading: React.FC<headingProps> = async ({ title, description }) => {
  return (
    <div>
      <h1 className="text-3xl font-bold tracking-tight">{title}</h1>
      <p className="text-sm text-muted-foreground">{description}</p>
    </div>
  );
};

export default Heading;
Avatar
it will become client component when it get imported to another client component
Answer
Avatar
American black bearOP
i see thx a lot, how can i close this ?
that was a stupid problem lol
Avatar
right click an answer > application > mark solution
Avatar
American black bearOP
@Raysorry, but i just remembered something, is it okay to make an async function inside a client function ? im doing it rn but no problems seems to happen
Avatar
yes you can use async function in client component
Avatar
American black bearOP
thx