I have a server component InitView;
const InitView = () => {
useEffect(() => { });
return (
<>
<Hero/>
<span className="text-xl font-normal text-gray-100">Now, how do you want to play?</span>
<GameModeMenu/>
</>
);
}
export default InitView;
Also I have one more server component View;
interface ViewProps {
children?: React.ReactNode;
}
const View = ({children}:ViewProps) => {
return (
<main className="home w-screen h-screen flex flex-col gap-10 justify-start items-center bg-neutral-900 px-8 py-10">
{children}
</main>
);
}
export default View;
And here is my page.tsx
export default function Page() {
return (
<View>
<InitView/>
</View>
)
}
When I tried to import the InitView inside the View component with pass-child method it throws an 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.
I'm completely okay with this error since I'm trying to use an effect inside a server component. However here is the thing , if I change my codes to this;
Page.tsx
export default function Page() {
return (
<View/>
)
}
View.tsx
"use client";
const View = () => {
return (
<main className="home w-screen h-screen flex flex-col gap-10 justify-start items-center bg-neutral-900 px-8 py-10">
<InitView/>
</main>
);
}
export default View;
The error is gone now. To clarify;
I can use an effect inside my InitView component without any "use client" markings since I directly imported it in View(marked as client) component.
I'm assuming every directly imported (server or client) components inside client components, will be client components, as the previous error says none of its parents are marked with "use client", so they're Server Components by default.
Have you guys any ideas? Am I wrong or correct?
P.S. The documentation says I can not import server components inside client components but as clearly can be seen, I can. I'm highly confused.