I get an error if i try to put a client component into a server component
Answered
Arboreal ant posted this in #help-forum
Arboreal antOP
Why can't i put a client component into a server component? i am importing the client component
import ServerList from "./components/ServerList";
import Head from 'next/head';
import { fetchServers } from "./actions/fetchServers";
export default async function Home() {
const servers = await fetchServers(1)
return (
<div className="home">
<ServerList searchQuery={ servers } />
</div>
);
} i get the error You're importing a component that needs useEffect. It only works in a Client Component but none of its parents are marked with "use client", so they're Server Components by default.Answered by joulev
does the
components/ServerList.js file have "use client" on the top?5 Replies
@joulev what is `ServerList`? does it have `useEffect`?
Arboreal antOP
yes
@Arboreal ant yes
does the
components/ServerList.js file have "use client" on the top?Answer
@joulev does the `components/ServerList.js` file have `"use client"` on the top?
Arboreal antOP
oh forgot to add that😅
it works now