Server vs Client Components
Server vs Client Components ~10 mins - nextjs

Server and Client Components

When to use Server and Client Components?

| Sno | Scenario | Server Component | Client Component |
| | ---------------------------------------------------------------------------- | ---------------- | ---------------- |
| 1 | Fetch data | Y | |
| 2 | Access backend resources (directly) | Y | |
| 3 | Keep sensitive information on the server (access tokens, API keys, etc) | Y | |
| 4 | Keep large dependencies on the server / Reduce client-side JavaScript | Y | |
| 5 | Add interactivity and event listeners (onClick(), onChange(), etc) | | Y |
| 6 | Use State and Lifecycle Effects (useState(), useReducer(), useEffect(), etc) | | Y |
| 7 | Use browser-only APIs | | Y |
| 8 | Use custom hooks that depend on state, effects, or browser-only APIs | | Y |
| 9 | Use React Class components | | Y |