Ever added "use client" somewhere in your Next.js app just because "it might need state" — and then wondered a week later?
"Wait… does this even need to be a client component?"
Yeah… we’ve all been there.
This is the story of Next Component Analyzer: the tool built to stop guessing and help you classify components correctly, every time.
🔍 From Developer Pain to Solution
Working with Next.js, I noticed a pattern: developers often overuse "use client". Why?
- They’re not sure if a component uses state or browser APIs
- They’re following a habit: “Better safe than sorry”
- A missed
"use client"can break hooks or event handlers
But overusing "use client" isn’t harmless — it can:
- Increase bundle size
- Move server-renderable components to the client unnecessarily
- Make your project harder to maintain , it wont just appear like that , but it can , you never know.
Wanted a way to audit components automatically and answer the question:
“Does this component really need to be a client component?”
That’s how Next Component Analyzer was like build me .
🛠 What Next Component Analyzer Does
Next Component Analyzer is your CLI sidekick for Next.js:
- Scans your entire project
- Detects React hooks, browser APIs, and JSX events
- Suggests whether a component should be Server or Client
- Highlights unnecessary
"use client"directives
It’s AST-based, so it doesn’t rely on naive string matching — no false positives here.
📊 Component Classifications
The analyzer classifies components into four meaningful categories:
| Category | What it means |
|---|---|
| Client Component (correct) | Has client features and "use client"
|
| Suggested: Client Component | Has client features but missing "use client"
|
| Suggested: Server Component | No client features, no "use client"
|
| Could be Server Component (unnecessary client) |
"use client" is present, but no client features |
⚡ Installation & CLI Usage
Run without installing:
npx next-component-analyzer
Or install globally:
npm install -g next-component-analyzer
next-component-analyzer
The CLI will scan your project and produce a classification report.
💻 Programmatic Usage
Perfect for CI pipelines, dashboards, or custom scripts:
import { analyzeProject } from "next-component-analyzer";
async function run() {
const results = await analyzeProject();
console.log(results);
}
run();
Example output:
[
{
"filePath": "app/page.tsx",
"classification": "server",
"detected": ["fetch"]
},
{
"filePath": "components/button.tsx",
"classification": "client",
"detected": ["useState", "useEffect"]
}
]
✅ Integrate results into CI checks, dashboards, or editor tools.
🌟 Why This Matters
Next Component Analyzer helps you:
- Keep your Next.js apps lean
- Avoid unnecessary client components
- Automatically enforce component architecture rules
- Reduce bugs caused by forgotten
"use client"directives
It turns guesswork into data-driven decisions, saving time and improving performance.
🧠 Philosophy
Every component should answer a simple question:
“Do I actually need to be a client component?”
Next Component Analyzer gives you the answer. By analyzing hooks, browser APIs, and events, it ensures intentional "use client" usage — no more guesswork, no more cluttered client bundles.
🔗 Try It Yourself
npx next-component-analyzer
Scan your Next.js project today and see exactly which components should be server, which should be client, and which might be overdoing it.
Here's the link to package : https://www.npmjs.com/package/next-component-analyzer
Top comments (0)