Next.js Discord

Discord Forum

Create client componet and server component in same file

Answered
Dwarf Crocodile posted this in #help-forum
Open in Discord
Dwarf CrocodileOP
I have some specific circumstances where i need to create a client component and server component in the same file. I can do it with multiple but i'm wondering, if for cleanliness i can do something like this.

const a = () => {
 return <div>Client</div>
}

const b = async() => {
"use server";
 return <div>Server</div>
}


but i just get It is not allowed to define inline "use server" annotated Server Actions in Client Components
Answered by Rafael Almeida
"use server" is a directive exclusive for server actions, it is not used for server components. so no you can't have them on the same file at the moment
View full answer

2 Replies

"use server" is a directive exclusive for server actions, it is not used for server components. so no you can't have them on the same file at the moment
Answer
Dwarf CrocodileOP
Ok thank you