Next.js App Router: 'You're importing a component that needs useState. It only works in a Client Component'
@devsingh05▲ 16 net votes
Files under app/ are Server Components by default, so hooks (useState, useEffect, useRouter from next/navigation), event handlers and browser APIs fail there. Put 'use client' as the first line of the file that uses them. Keep it as low in the tree as possible: make a small client component for the interactive part and import it from the server page so data fetching stays on the server. useRouter must come from next/navigation in app/, not next/router.