nextjs-best-practice
1
总安装量
1
周安装量
#77474
全站排名
安装命令
npx skills add https://github.com/lvncer/ai-configs --skill nextjs-best-practice
Agent 安装分布
amp
1
cline
1
opencode
1
cursor
1
kimi-cli
1
codex
1
Skill 文档
Next.js Best Practice
ãã£ã¬ã¯ããªæ§é
src/
âââ app/ # Next.js App Router - ã«ã¼ãã£ã³ã°ã¨ãã¼ã¸
âââ components/
â âââ ui/ # Shadcn/ui ã³ã³ãã¼ãã³ã - åå©ç¨å¯è½ãª UI ããªããã£ã
â âââ layouts/ # ä¸è²«ãããã¼ã¸æ§é ã®ããã®ã¬ã¤ã¢ã¦ãã³ã³ãã¼ãã³ã
âââ hooks/ # å
±æãã¸ãã¯ã®ããã®ã«ã¹ã¿ã React ããã¯
âââ types/ # TypeScript åå®ç¾©
âââ lib/
â âââ constants/ # ã¢ããªã±ã¼ã·ã§ã³å®æ°ã¨è¨å®
â âââ utils/ # ã¦ã¼ãã£ãªãã£é¢æ°ã¨ãã«ãã¼
â âââ actions/ # Server Actionsï¼ãµã¼ãã¼ãµã¤ãã®ãã¥ã¼ãã¼ã·ã§ã³ï¼
â âââ services/ # ãã¡ã¤ã³ãµã¼ãã¹ï¼ãã¸ãã¹ãã¸ãã¯ãå¤é¨APIå¼ã³åºãçï¼
âââ tests/
âââ unit/ # åå¥ã®é¢æ°/ã³ã³ãã¼ãã³ãã®ã¦ããããã¹ã
âââ integration/ # ã³ã³ãã¼ãã³ãç¸äºä½ç¨ã®çµ±åãã¹ã
âââ e2e/ # å®å
¨ãªã¦ã¼ã¶ã¼ããã¼ã®ã¨ã³ããã¼ã¨ã³ããã¹ã
ãã¡ã¤ã«å½åè¦å
- Pages:
page.tsx– Next.js App Router ã®ãã¼ã¸ã³ã³ãã¼ãã³ã - Layouts:
layout.tsx– ã«ã¼ãã°ã«ã¼ãã®å ±æã¬ã¤ã¢ã¦ãã³ã³ãã¼ãã³ã - Loading:
loading.tsx– ã«ã¼ãã»ã°ã¡ã³ãã®ãã¼ãã£ã³ã° UI - Errors:
error.tsx– ã«ã¼ãã»ã°ã¡ã³ãã®ã¨ã©ã¼å¢çã³ã³ãã¼ãã³ã - APIs:
route.ts– ãµã¼ãã¼ã¨ã³ããã¤ã³ãã® API ã«ã¼ããã³ãã©ã¼
ã³ã³ãã¼ãã³ãè¨è¨åå
- Server Components (ããã©ã«ã): ãã¼ã¿ãã§ãããSEO æé©åãéçã³ã³ãã³ãã®ã¬ã³ããªã³ã°ã«ä½¿ç¨
- Client Components (å¿ è¦ãªå ´å): ãã©ã¦ã¶ APIãã¤ãã³ããªã¹ãã¼ãã¾ã㯠React ããã¯ãå¿ è¦ãªå ´åã®ã¿ä½¿ç¨
- ç¶æ¿ãããã³ã³ãã¸ã·ã§ã³: å°ããªç¦ç¹ãçµã£ãã³ã³ãã¼ãã³ããçµã¿åããã¦è¤é㪠UI ãæ§ç¯
API è¨è¨ãã¿ã¼ã³
- GET API ãªã: API ã«ã¼ãã®ä»£ããã« Server Components ã使ç¨ãã¦ãã¼ã¿ãã§ãã
- Server Actions ãåªå : ãã©ã¼ã éä¿¡ã¨ãã¥ã¼ãã¼ã·ã§ã³ã«ã¯ Server Actions ã使ç¨
- å¤é¨çµ±åç¨ã® API ã«ã¼ã: ã¦ã§ãããã¯ã¨ãµã¼ããã¼ãã£çµ±åã«ã®ã¿ POST/PATCH/PUT/DELETE ã使ç¨
- åå®å ¨æ§: ãªã¯ã¨ã¹ã/ã¬ã¹ãã³ã¹æ¤è¨¼ã«ã¯å¸¸ã« Zod ã¹ãã¼ãã使ç¨
Server Actions ã®é ç½®æ¹é
- å
±æ/ãã¡ã¤ã³æ¨ªæç㪠Server Actions ã¯
lib/actions/ã«é ç½®ãã - ã«ã¼ãå°ç¨ã®å°ã㪠Server Actions ã¯ãå¿
è¦ã«å¿ãã¦è©²å½ã«ã¼ãç´ä¸ï¼ä¾:
app/(group)/feature/actions.tsï¼ã«ç½®ãã¦ããã - ãã¡ã¤ã«å½åã¯åè©ãã¼ã¹ã§ã1 ãã¡ã¤ã« = 1 æ¦å¿µï¼ä¾:
user.ts,post.tsï¼ãååã¨ããindex.tsã§åã¨ã¯ã¹ãã¼ãã許容
hooks / services / actions ã®ä½¿ãåã
hooksï¼ã¯ã©ã¤ã¢ã³ãå°ç¨ï¼: React ã®ç¶æ ã»å¯ä½ç¨ã»UI 飿ºã«é¢ãããã¸ãã¯ããã©ã¦ã¶ APIãã¤ãã³ããã³ããªã³ã°ããã©ã¼ã ç¶æ ãªã© UI å¯ãã®è²¬åservicesï¼ãµã¼ãã¼/ã¯ã©ã¤ã¢ã³ãå ±æå¯ï¼: ãã¸ãã¹ãã¸ãã¯ãå¤é¨ API å¼ã³åºããããªããã£ãã®çµã¿åãããªã©ãç´ç²é¢æ°ä¸å¿ã§å®è£ ãå¯ä½ç¨ã¯æ½è±¡åããã¹ãå®¹ææ§ãæåªå actionsï¼ãµã¼ãã¼å°ç¨ï¼: ãã©ã¼ã éä¿¡ããã¥ã¼ãã¼ã·ã§ã³ã®å ¥å£ãèªè¨¼/èªå¯ãå ¥åæ¤è¨¼ï¼Zodï¼ããã©ã³ã¶ã¯ã·ã§ã³å¶å¾¡ãservicesã®ãªã¼ã±ã¹ãã¬ã¼ã·ã§ã³ãæ å½
ã¬ã¤ãã©ã¤ã³:
hooks㯠UI ããactionsãå¼ã³åºãããã®èãæ©æ¸¡ãã«çãã- ãã¸ãã¹ã«ã¼ã«ã¯å¯è½ãªéã
servicesã«éç´ããactions㯠I/O ã¨ãªã¼ã±ã¹ãã¬ã¼ã·ã§ã³ã«å°å¿µ servicesã¯å¯ä½ç¨å¢çãæç¢ºåãããã¹ãã§ã¯ã¢ãã¯ã§ç½®ãæãå¯è½ã«ãã