useState. What will happen when this component is rendered?import React, { useState } from 'react'; export default function ServerComp() { const [count, setCount] = useState(0); return <div>{count}</div>; }
Server Components in Next.js cannot use React hooks like useState because these hooks require client-side interactivity. Attempting to use them causes a runtime error.
The useEffect hook is a client-side React hook and cannot be used or imported in Server Components. The other imports are Node.js or server-safe modules.
export default function ServerComp() { const date = new Date().toLocaleTimeString(); return <div>{date}</div>; }
The Server Component renders the current time string at build or request time. When React hydrates on the client, the time is different, causing a mismatch warning.
React hooks like useState and useEffect require client-side interactivity and are disallowed in Server Components. The other operations are allowed.
count after rendering this Server Component?count when rendered.let count = 0; export default function ServerComp() { count += 1; return <div>{count}</div>; }
The module containing the Server Component is cached on the server. Top-level variables like count persist across requests. Each request invokes the component function, incrementing count and rendering the updated value.