Review and write React/Next.js code following Page Driven Development principles...
Code should be organized by context, not by technology or false separation of concerns. Components belong near the pages that use them, not in global shared directories.
Place components in the same directory as the page that uses them:
app/
dashboard/
page.tsx
dashboard-header.tsx # Only used by dashboard
dashboard-stats.tsx # Only used by dashboard
settings/
page.tsx
settings-form.tsx # Only used by settings
NOT in a global components folder:
# Avoid this pattern
components/
DashboardHeader.tsx
DashboardStats.tsx
SettingsForm.tsx
Do not abstract components globally just because they "could" be reused. A component used in multiple pages with vastly different contexts creates tangled coupling.
Ask yourself:
If the contexts differ, keep separate implementations.
PDD does not mean monolithic pages. Decompose naturally:
useState calls in a component is a code smellOnly create truly global components for:
It's better to have similar code in two places than a fragile abstraction that serves neither well. Duplication is cheaper than the wrong abstraction.
Check for:
useState in page root