Skip to content

Commit 6f71e67

Browse files
authored
Enhance documentation for route-action-gen workflow and React components (#18)
- Updated the route-action-gen workflow description to include server actions/functions. - Added a new section in TypeScript/JavaScript standards for React Server Action/Function, referencing the route-action-gen workflow. - Improved the data & mutations section in the React component skill documentation to clarify the use of route-action-gen for data fetching and server actions. Co-authored-by: Nico Prananta <311343+nicnocquee@users.noreply.github.com>
1 parent 7d6c19e commit 6f71e67

File tree

4 files changed

+52
-10
lines changed

4 files changed

+52
-10
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
description: Ensure planned todos follow TypeScript/JavaScript standards
3+
alwaysApply: true
4+
---
5+
6+
# Planning with TS/JS Standards
7+
8+
When creating a plan or todo list for a TypeScript or JavaScript project, every todo item must account for the standards in the `typescript-javascript-standards` rule.
9+
10+
Each planned task should include relevant steps for:
11+
12+
- **JSDoc comments** on every new or modified function.
13+
- **Dependency injection** — accept collaborators as parameters with production defaults.
14+
- **Unit tests** with 100% coverage, co-located as `.test.ts` / `.test.js` files.
15+
- **Kebab-case file naming** for any new files.
16+
- **Linter & TypeScript error resolution** before marking a task complete.
17+
18+
```
19+
❌ BAD — missing standards steps
20+
1. Create fetchUsers function
21+
2. Wire it up in the component
22+
23+
✅ GOOD — includes standards
24+
1. Create fetchUsers function with JSDoc, accepting db client via DI
25+
2. Add fetchUsers.test.ts with 100% coverage using a fake db
26+
3. Wire it up in the component with production default
27+
4. Resolve all linter/TS errors
28+
```

.cursor/rules/route-action-gen-workflow.mdc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
---
2-
description: Workflow for creating Next.js route handlers (App Router) or API routes (Pages Router) using route-action-gen
2+
description: Workflow for creating Next.js route handlers (App Router), API routes (Pages Router) and server actions/functions using route-action-gen
33
globs: "**/route.*.config.ts"
44
alwaysApply: false
55
---
66

77
# Route Action Gen Workflow
88

9-
When creating a new route handler or API route, always use `route-action-gen`.
9+
When creating a new route handler, API route or server action/function, always use `route-action-gen`.
1010

1111
## Step 1: Create the config file
1212

.cursor/rules/typescript-javascript-standards.mdc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,11 @@ test("getActiveUsers returns only active users", async () => {
9191
## React component
9292

9393
Use the /react-component skill when creating a React component.
94+
95+
## React Server Action/Function
96+
97+
Follow the /route-action-gen-workflow rule when creating a server action/function.
98+
99+
## Next.js Route Handler/API Route
100+
101+
Follow the /route-action-gen-workflow rule when creating a Next.js route handler/API route.

.cursor/skills/react-component/SKILL.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,20 @@ Apply these in order of preference:
3333

3434
## Data & Mutations
3535

36-
| Scenario | Approach |
37-
|----------|----------|
38-
| Data mutation | Server Action + `useActionState` |
39-
| Server action coupling | Accept server action via **props** (dependency injection) |
40-
| Client-side fetching | `useSWR` + API Route Handler |
41-
| Input validation | **Zod** in every server action and API endpoint |
36+
| Scenario | Approach |
37+
| ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
38+
| Data mutation | Server Action + `useActionState` using `route-action-gen`. See the `/route-action-gen-workflow` rule for more details. |
39+
| Server action coupling | Accept server action via **props** (dependency injection) |
40+
| Client-side fetching | Use the generated files by `route-action-gen` to fetch data from the server action or API end point/route handler. See the `/route-action-gen-workflow` rule for more details. |
41+
| Input validation | **Zod** in every server action and API endpoint |
4242

4343
```tsx
4444
// Server action injected via props
45-
const CreatePostForm = ({ createPost }: { createPost: (fd: FormData) => Promise<State> }) => {
45+
const CreatePostForm = ({
46+
createPost,
47+
}: {
48+
createPost: (fd: FormData) => Promise<State>;
49+
}) => {
4650
const [state, formAction, pending] = useActionState(createPost, initialState);
4751
return <form action={formAction}>...</form>;
4852
};
@@ -87,7 +91,9 @@ const DataTable = ({ children }: { children: React.ReactNode }) => (
8791
const DataTableHeader = ({ columns }: { columns: string[] }) => (
8892
<TableHeader>
8993
<TableRow>
90-
{columns.map((col) => <TableHead key={col}>{col}</TableHead>)}
94+
{columns.map((col) => (
95+
<TableHead key={col}>{col}</TableHead>
96+
))}
9197
</TableRow>
9298
</TableHeader>
9399
);

0 commit comments

Comments
 (0)