Agent skill
nextjs-write
Write or refactor Next.js (TypeScript/React) code using Next.js best practices with reuse-first implementation. Use when implementing frontend pages/components/features in Next.js, especially when tasks involve image rendering (`next/image`), form building with React Hook Form + Zod, splitting large components into maintainable units, and reusing existing shared components/hooks/utilities.
Install this agent skill to your Project
npx add-skill https://github.com/shaowei-g/codex-skills/tree/main/skills/nextjs-write
SKILL.md
Next.js Write (Reuse-First, Maintainable, RHF + Zod)
Use this skill when implementing or refactoring Next.js (TypeScript/React) code in a TypeScript/React codebase.
Core Requirements (Must Follow)
- Use
next/image(<Image />) for rendering images. - Reuse existing code before creating anything new:
- Functional components (FCs)
- Hooks
- Utilities and constants
- UI primitives
- Prioritize
global/,shared/,components/,ui/,hooks/,lib/,utils/
- Keep FCs small and single-responsibility:
- Split large components into
XxxSection,XxxForm,XxxField,XxxList,XxxItem. - Keep helper functions near usage.
- Split large components into
- Build forms with React Hook Form + Zod by default:
- Use
zodResolverfrom@hookform/resolvers/zod.
- Use
Autonomous Development Workflow
- Do not read or edit files outside the project folder.
- Work autonomously in small, testable increments.
- Understand existing routing, data fetching, and UI patterns before implementing.
- Do not commit changes.
- After implementation, run project checks in expected order. If available, use
typescript-postcheck.
Reuse-First Search Strategy (Required)
Before creating new code:
- Find an existing component matching UX/layout.
- Find an existing hook matching state/data/side-effect needs.
- Find existing utilities for parsing, formatting, API calls, and error handling.
- Create the smallest possible new code only when reuse is not viable.
When reuse is not possible, state the reason clearly:
- API mismatch
- Missing variant
- Coupling constraints
- Performance constraints
Next.js Conventions
Routing and Rendering
- Prefer Server Components for data fetching and composition when using App Router.
- Use Client Components only when needed (state, effects, handlers, RHF).
- Keep server/client boundaries explicit (
"use client"only where required).
Data Fetching
- Reuse existing fetch wrappers from
lib/api,services, orclientwhen present. - Avoid ad-hoc fetch logic in multiple components.
- Handle loading and error states consistently with existing patterns.
Images
- Always:
import Image from "next/image";- Provide
alt - Provide
width/heightor usefillwith a sized parent - Provide
sizesfor responsive layouts when applicable
React Component Style (Maintainable FCs)
- Keep components small and focused.
- Use
Propsinterfaces. - Use early returns for empty/error states.
- Avoid deeply nested JSX; extract subcomponents.
- Colocate state with the smallest responsible owner.
Forms (React Hook Form + Zod First)
When building forms:
- Define or reuse a Zod schema near the form.
- Infer types with
type FormValues = z.infer<typeof schema>. - Use
useForm<FormValues>({ resolver: zodResolver(schema), defaultValues }). - Use
FormProviderand small field components when readability improves. - Use
Controlleronly for non-native/custom inputs.
Required Zod practices:
- Reuse schemas from
global/orshared/when available. - Keep schemas narrow and aligned with real constraints.
- Prefer
.trim(),.min(),.max(),.email(), and explicit messages. - Validate at boundaries (for example API payloads), not only in UI.
Typical structure:
XxxFormowns schema,useForm, submitXxxFieldsgroups field layoutsXxxFieldencapsulates single reusable field
Anti-Patterns to Avoid
- Avoid
<img>instead ofnext/image. - Avoid duplicating existing shared/global components/hooks/schemas.
- Avoid large multi-responsibility "God components."
- Avoid speculative abstractions with one caller.
- Avoid hand-rolled validation when RHF + Zod is available.
Suggested Workflow (Checklist)
- Identify the closest existing page/component pattern.
- Search shared/global directories for reusable FCs/hooks/utils/schemas.
- Implement the smallest change using small components.
- Use RHF + Zod for forms by default.
- Ensure all images use
next/image. - Run targeted checks/tests, then lint/typecheck per repo convention.
- Keep diffs focused and reviewable.
Output Expectations
- Mention which components/hooks/utils/schemas were reused and from where.
- Keep new components small and clearly named.
- Use
next/imagefor all image rendering. - Use React Hook Form + Zod validation by default for forms.
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
brainstorming
You MUST use this before any creative work - creating features, building components, adding functionality, or modifying behavior. Explores user intent, requirements and design before implementation.
ekoen-frontend-code-review
Production-grade code review for the eKoEN frontend codebase. Use when asked to review, audit, inspect, or harden eKoEN React/Next.js frontend code, pages, components, hooks, API clients, or state layers for bugs, performance bottlenecks, TypeScript safety issues, request inefficiency, state-management risks, memory leaks, rendering regressions, error-handling gaps, duplication, or maintainability problems, especially when a structured severity-ranked report with code locations, root causes, suggested fixes, and example refactors is required.
ekoen-backend.doc.route-error
Add HttpErrorRes responses to eKoEN backend routes when controllers can throw errors from app/util/errors/index.ts
conventional-commit-helper
Generate and validate Conventional Commit messages for semantic-release workflows. Use when a user asks to write a commit message, asks to commit changes, asks for commit type/scope selection, or asks to enforce Conventional Commits consistency.
codex-cli-subagent-transport
Use only when native subagent execution is unavailable and the caller needs one deterministic Codex CLI run with repo-local artifacts and a manifest-based result contract.
skill-usage-logger
All skill MUST use this logger to record usage events in NDJSON format.Log Codex skill usage events to NDJSON with safe concurrent appends.
Didn't find tool you were looking for?