nextjs-anti-patterns
БесплатноБез исполняемых скриптовНе проверенIdentify and fix common Next.js App Router anti-patterns and mistakes. Use when reviewing code for Next.js best practices, debugging performance issues…
Об этом скилле
Next.js Anti-Patterns
Overview
Identify and correct common anti-patterns in Next.js App Router applications, focusing on misuse of useEffect, improper data fetching, unnecessary client-side state, and incorrect component boundaries.
TypeScript: NEVER Use any Type
CRITICAL RULE: This codebase has @typescript-eslint/no-explicit-any enabled. Using any will cause build failures.
❌ WRONG:
function handleSubmit(e: any) { ... }
const data: any[] = [];
✅ CORRECT:
function handleSubmit(e: React.FormEvent<HTMLFormElement>) { ... }
const data: string[] = [];
Common Next.js Type Patterns
// Page props
function Page({ params }: { params: { slug: string } }) { ... }
function Page({ searchParams }: { searchParams: { [key: string]: string | string[] | undefined } }) { ... }
// Form events
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => { ... }
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => { ... }
// Server actions
async function myAction(formData: FormData) { ... }
When to Use This Skill
Use this skill when:
- Reviewing Next.js code for best practices
- Debugging performance issues in App Router apps
- Migrating from Pages Router with legacy patterns
- Code shows excessive client-side JavaScript
- Components are using useEffect unnecessarily
- Detecting waterfall data fetching patterns
- Identifying incorrect Server/Client component usage
Rendering Responsibilities
When requirements call for a page or component to present specific UI (e.g., display a banner or guard message), place that rendering responsibility in the exported component that callers actually use. Helper components are fine, but make sure they are composed so the main entry point still outputs the expected elements.
Recommended Pattern
// page.tsx
'use client';
import { BrowserGuard } from './BrowserGuard';
export default function Page() {
return <BrowserGuard />;
}
// BrowserGuard.tsx
'use client';
export function BrowserGuard() {
const isSafari = typeof navigator !== 'undefined' &&
/Safari/.test(navigator.userAgent) &&
!/Chrome/.test(navigator.userAgent);
if (isSafari) {
return <h1>Unsupported Browser</h1>;
}
return <h1>Welcome</h1>;
}
This keeps the logic modular while ensuring the visible component still renders the appropriate message. Apply the same principle to other requirements—compose helpers, but never leave the primary component without the mandated UI.
Anti-Pattern Categories
Category 1: Inappropriate useEffect Usage
Anti-Pattern 1.1: Using useEffect for Browser Detection
❌ WRONG - useEffect with useState:
'use client';
import { useEffect, useState } from 'react';
export default function BrowserCheck() {
const [isSafari, setIsSafari] = useState(false);
useEffect(() => {
setIsSafari(/Safari/.test(navigator.userAgent));
}, []);
return <div>{isSafari ? 'Unsupported' : 'Welcome'}</div>;
}
Why it's wrong:
- Causes flash of wrong content (renders default, then updates)
- Unnecessary client-side state management
- Can be detected directly in component body
- Creates hydration mismatch
✅ CORRECT - Direct browser detection in component body:
'use client';
export default function BrowserCheck() {
// Direct detection without useState or useEffect
const isSafari = typeof navigator !== 'undefined' &&
/Safari/.test(navigator.userAgent) &&
!/Chrome/.test(navigator.userAgent);
const isFirefox = typeof navigator !== 'undefined' &&
/Firefox/.test(navigator.userAgent);
if (isSafari || isFirefox) {
return <h1>Unsupported Browser</h1>;
}
return <h1>Welcome</h1>;
}
Key points:
- Use
typeof navigator !== 'undefined'for SSR safety - Direct detection in component body (no hooks)
- Use conditional rendering, not useState
- Safari detection should exclude Chrome (
!/Chrome/.test(...)) - Implement directly in the component OR create a helper and import it into the exported entry point
- Ensure the logic is accessible from the component that consumers will render
Alternative: Use CSS media queries for responsive:
export default function ResponsiveComponent() {
return (
<div>
<div className="block md:hidden"><MobileView /></div>
<div className="hidden md:block"><DesktopView /></div>
</div>
);
}
Anti-Pattern 1.2: Using useEffect for Data Fetching
Wrong:
'use client';
import { useEffect, useState } from 'react';
export default function BlogPosts() {
const [posts, setPosts] = useState([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);
useEffect(() => {
fetch('/api/posts')
.then(res => res.json())
.then(data => {
setPosts(data);
setLoading(false);
})
.catch(err => {
setError(err);
setLoadi
Установить nextjs-anti-patterns в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
ReadWriteEditGlobGrepBashFAQ
Что делает скилл nextjs-anti-patterns?
Identify and fix common Next.js App Router anti-patterns and mistakes. Use when reviewing code for Next.js best practices, debugging performance issues, migrating from Pages Router patterns, or preventing common pitfalls. Activates for code review, performance optimization, or detecting inappropriate useEffect/useState usage. CRITICAL: For browser detection, keep the logic in the user-facing component (or a composed helper that it renders) rather than isolating it in unused files.
Как установить скилл nextjs-anti-patterns?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл nextjs-anti-patterns запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic