Instructions for Next.js 16 Client Components
For Client Components in Next.js 16:
- •
Declaration: Add
'use client';at the top of the file to mark as Client Component. - •
Use Cases:
- •Interactivity: Event handlers (onClick, etc.).
- •State:
useState,useReducer. - •Effects:
useEffectfor side effects. - •Browser APIs: Access to
window,document.
- •
Hooks:
- •Routing:
useRouter,usePathname,useSearchParamsfromnext/navigation. - •Context:
useContextfor shared state.
- •Routing:
- •
Integration with Server Components:
- •Client Components can be children of Server Components.
- •Receive props from Server Components (must be serializable).
- •
Optimization:
- •Minimize client bundle size by keeping non-interactive parts as Server Components.
- •Use
Suspenseboundaries for loading states.
- •
Third-Party Libraries:
- •Install and use client-side libs like React Query for data fetching.
- •
Best Practices:
- •Avoid server-only code in Client Components.
- •Handle hydration mismatches carefully.
- •Use TypeScript for better type safety with hooks.
References
Use the shared references located at: ../_shared/reference.md