Encountered some weird issues regarding server/client components
Unanswered
Haddock posted this in #help-forum
HaddockOP
Why does console log runs both in server and in client?
'use client';
import React, { PropsWithChildren, useState } from 'react';
import style from './style.module.scss';
import { Cross2Icon } from '@radix-ui/react-icons';
import { useNavContext } from '@/context/HeaderProvider';
const Container = ({ children }: PropsWithChildren) => {
const [menuState, setMenuState] = useState('close');
const { sideMenuState, closeMobileMenu } = useNavContext();
console.log('this should not run in backend');
return (
<nav data-state={sideMenuState} className={style.rootContainer}>
<Cross2Icon
style={{ cursor: 'pointer' }}
className={style.closeIcon}
onClick={closeMobileMenu}
/>
{children}
</nav>
);
};
export default Container;
2 Replies
HaddockOP
Just read docs, nextjs prerender the file even if this is client
yeah, Next.js still pre-render client components