@ranimontagna/agent-toolkit 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +42 -8
- package/package.json +1 -1
- package/skills/frontend/react/react-patterns/LICENSE +21 -0
- package/skills/frontend/react/react-patterns/NOTICE.md +11 -0
- package/skills/frontend/react/react-patterns/SKILL.md +341 -0
- package/skills/frontend/react/react-performance/LICENSE +21 -0
- package/skills/frontend/react/react-performance/NOTICE.md +11 -0
- package/skills/frontend/react/react-performance/SKILL.md +574 -0
- package/skills/frontend/react/react-testing/LICENSE +21 -0
- package/skills/frontend/react/react-testing/NOTICE.md +11 -0
- package/skills/frontend/react/react-testing/SKILL.md +423 -0
- package/skills/frontend/react-native/react-native-expert/LICENSE +21 -0
- package/skills/frontend/react-native/react-native-expert/NOTICE.md +11 -0
- package/skills/frontend/react-native/react-native-expert/SKILL.md +187 -0
- package/skills/frontend/react-native/react-native-expert/references/expo-router.md +187 -0
- package/skills/frontend/react-native/react-native-expert/references/list-optimization.md +204 -0
- package/skills/frontend/react-native/react-native-expert/references/platform-handling.md +188 -0
- package/skills/frontend/react-native/react-native-expert/references/project-structure.md +171 -0
- package/skills/frontend/react-native/react-native-expert/references/storage-hooks.md +173 -0
- package/skills/frontend/react-native/react-native-unistyles-v3/LICENSE +21 -0
- package/skills/frontend/react-native/react-native-unistyles-v3/NOTICE.md +11 -0
- package/skills/frontend/react-native/react-native-unistyles-v3/SKILL.md +159 -0
- package/skills/frontend/react-native/react-native-unistyles-v3/references/api-reference.md +495 -0
- package/skills/frontend/react-native/react-native-unistyles-v3/references/common-issues.md +389 -0
- package/skills/frontend/react-native/react-native-unistyles-v3/references/setup-guide.md +217 -0
- package/skills/frontend/react-native/react-native-unistyles-v3/references/styling-patterns.md +705 -0
- package/skills/frontend/react-native/react-native-unistyles-v3/references/third-party-integration.md +318 -0
package/README.md
CHANGED
|
@@ -131,6 +131,19 @@ skills/
|
|
|
131
131
|
fastify-best-practices/
|
|
132
132
|
SKILL.md
|
|
133
133
|
rules/
|
|
134
|
+
frontend/
|
|
135
|
+
react-native/
|
|
136
|
+
react-native-expert/
|
|
137
|
+
SKILL.md
|
|
138
|
+
react-native-unistyles-v3/
|
|
139
|
+
SKILL.md
|
|
140
|
+
react/
|
|
141
|
+
react-patterns/
|
|
142
|
+
SKILL.md
|
|
143
|
+
react-performance/
|
|
144
|
+
SKILL.md
|
|
145
|
+
react-testing/
|
|
146
|
+
SKILL.md
|
|
134
147
|
```
|
|
135
148
|
|
|
136
149
|
The first path segment is a selectable package:
|
|
@@ -158,6 +171,12 @@ Use `--skills-scope` to select a narrower path:
|
|
|
158
171
|
npx -y @ranimontagna/agent-toolkit --skills-only --codex --skills-scope backend/node
|
|
159
172
|
```
|
|
160
173
|
|
|
174
|
+
Install only React Native skills:
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
npx -y @ranimontagna/agent-toolkit --skills-only --codex --skills-scope frontend/react-native
|
|
178
|
+
```
|
|
179
|
+
|
|
161
180
|
Both filters can be combined. The selected package filter runs first, then the
|
|
162
181
|
scope filter narrows the result.
|
|
163
182
|
|
|
@@ -188,6 +207,11 @@ Follow these steps...
|
|
|
188
207
|
|---|---|---|
|
|
189
208
|
| `core` | `agent-toolkit-maintainer` | Maintained in this repository |
|
|
190
209
|
| `backend` | `fastify-best-practices` | Copied from Matteo Collina's [`mcollina/skills`](https://github.com/mcollina/skills/tree/main/skills/fastify) under the MIT license |
|
|
210
|
+
| `frontend` | `react-native-expert` | Copied from Jeffallan's [`claude-skills`](https://github.com/Jeffallan/claude-skills/tree/main/skills/react-native-expert) under the MIT license |
|
|
211
|
+
| `frontend` | `react-native-unistyles-v3` | Copied from Jacek Pudysz's [`react-native-unistyles`](https://github.com/jpudysz/react-native-unistyles/tree/main/skills/react-native-unistyles-v3), declared MIT upstream |
|
|
212
|
+
| `frontend` | `react-patterns` | Copied from Affaan Mustafa's [`ECC`](https://github.com/affaan-m/ECC/tree/main/skills/react-patterns) under the MIT license |
|
|
213
|
+
| `frontend` | `react-performance` | Copied from Affaan Mustafa's [`ECC`](https://github.com/affaan-m/ECC/tree/main/skills/react-performance) under the MIT license |
|
|
214
|
+
| `frontend` | `react-testing` | Copied from Affaan Mustafa's [`ECC`](https://github.com/affaan-m/ECC/tree/main/skills/react-testing) under the MIT license |
|
|
191
215
|
|
|
192
216
|
The installer validates:
|
|
193
217
|
|
|
@@ -197,9 +221,9 @@ The installer validates:
|
|
|
197
221
|
- `name` uses lowercase letters, numbers and hyphens;
|
|
198
222
|
- `description` is non-empty and under 1024 characters.
|
|
199
223
|
|
|
200
|
-
Third-party frontend design skills
|
|
201
|
-
The `frontend-skills` tool installs them
|
|
202
|
-
from pinned public sources.
|
|
224
|
+
Third-party frontend design skills such as Impeccable and Taste Skill are not
|
|
225
|
+
vendored as bundled Custom Skills. The `frontend-skills` tool installs them
|
|
226
|
+
externally through the Agent Skills CLI from pinned public sources.
|
|
203
227
|
|
|
204
228
|
## CLI Reference
|
|
205
229
|
|
|
@@ -315,9 +339,16 @@ Current external sources:
|
|
|
315
339
|
| Frontend Skills | `skills@1.5.10`, `pbakaus/impeccable` and `Leonxlnx/taste-skill` at pinned commits | Clones pinned refs before install |
|
|
316
340
|
| Runtime CLIs | Exact npm versions for Claude, Codex, OpenCode and Gemini | Used only when `--install-missing-clis` is enabled |
|
|
317
341
|
|
|
318
|
-
Bundled third-party skills preserve upstream attribution and license files
|
|
319
|
-
|
|
320
|
-
|
|
342
|
+
Bundled third-party skills preserve upstream attribution and license files:
|
|
343
|
+
|
|
344
|
+
| Skill | Source commit | License |
|
|
345
|
+
|---|---|---|
|
|
346
|
+
| `fastify-best-practices` | `mcollina/skills@5b2a81354b6d10325da0db9decc9ce5ecc714138` | MIT |
|
|
347
|
+
| `react-native-expert` | `Jeffallan/claude-skills@e8be415bc94d8d6ebddc2fb50e5d03c6e27d4319` | MIT |
|
|
348
|
+
| `react-native-unistyles-v3` | `jpudysz/react-native-unistyles@8b5e9fd281a81bdfd87d4fe9e6a0b042c84c5c83` | MIT |
|
|
349
|
+
| `react-patterns` | `affaan-m/ECC@0f84c0e2796703fbda87d577b2636351418c7442` | MIT |
|
|
350
|
+
| `react-performance` | `affaan-m/ECC@0f84c0e2796703fbda87d577b2636351418c7442` | MIT |
|
|
351
|
+
| `react-testing` | `affaan-m/ECC@0f84c0e2796703fbda87d577b2636351418c7442` | MIT |
|
|
321
352
|
|
|
322
353
|
Releases use npm trusted publishing through GitHub Actions OIDC. The npm
|
|
323
354
|
package is published without a long-lived npm token, and npm automatically
|
|
@@ -353,6 +384,9 @@ skills/
|
|
|
353
384
|
fastify-best-practices/
|
|
354
385
|
SKILL.md
|
|
355
386
|
rules/
|
|
387
|
+
frontend/
|
|
388
|
+
react-native/
|
|
389
|
+
react/
|
|
356
390
|
tests/
|
|
357
391
|
unit/
|
|
358
392
|
test-agent-toolkit.sh
|
|
@@ -429,8 +463,8 @@ Release a new npm version by updating `package.json`, pushing the change to
|
|
|
429
463
|
`main`, then pushing a matching tag:
|
|
430
464
|
|
|
431
465
|
```bash
|
|
432
|
-
git tag v0.1.
|
|
433
|
-
git push origin v0.1.
|
|
466
|
+
git tag v0.1.6
|
|
467
|
+
git push origin v0.1.6
|
|
434
468
|
```
|
|
435
469
|
|
|
436
470
|
The `Release` workflow runs the full check and publishes the scoped package to
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ranimontagna/agent-toolkit",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "Personal AI agent toolkit installer for Claude Code, Codex CLI, OpenCode, Gemini CLI and graph-aware workflows.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"packageManager": "pnpm@11.0.6",
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Affaan Mustafa
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Attribution
|
|
2
|
+
|
|
3
|
+
This skill is copied from Affaan Mustafa's public `affaan-m/ECC` repository.
|
|
4
|
+
|
|
5
|
+
- Source: https://github.com/affaan-m/ECC/tree/main/skills/react-patterns
|
|
6
|
+
- Imported from commit: `0f84c0e2796703fbda87d577b2636351418c7442`
|
|
7
|
+
- Upstream skill name: `react-patterns`
|
|
8
|
+
- License: MIT
|
|
9
|
+
- Copyright: Copyright (c) 2026 Affaan Mustafa
|
|
10
|
+
|
|
11
|
+
The upstream MIT license text is preserved in `LICENSE`.
|
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: react-patterns
|
|
3
|
+
description: React 18/19 patterns including hooks discipline, server/client component boundaries, Suspense + error boundaries, form actions, data fetching, state management decision trees, and accessibility-first composition. Use when writing or reviewing React components.
|
|
4
|
+
origin: ECC
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# React Patterns
|
|
8
|
+
|
|
9
|
+
Idiomatic React 18/19 patterns for building robust, accessible, performant component trees.
|
|
10
|
+
|
|
11
|
+
## When to Activate
|
|
12
|
+
|
|
13
|
+
- Writing or modifying React function components, custom hooks, or component trees
|
|
14
|
+
- Reviewing JSX/TSX files
|
|
15
|
+
- Designing state shape or component composition
|
|
16
|
+
- Migrating class components or older `forwardRef`/`useEffect`-heavy code
|
|
17
|
+
- Choosing between local state, lifted state, context, and external stores
|
|
18
|
+
- Working with Server Components / Client Components (Next.js App Router, RSC)
|
|
19
|
+
- Implementing forms with React 19 actions or controlled inputs
|
|
20
|
+
- Wiring data fetching with TanStack Query / SWR / RSC
|
|
21
|
+
|
|
22
|
+
## Core Principles
|
|
23
|
+
|
|
24
|
+
### 1. Render is a Pure Function of Props and State
|
|
25
|
+
|
|
26
|
+
```tsx
|
|
27
|
+
// Good: derive during render
|
|
28
|
+
function Cart({ items }: { items: CartItem[] }) {
|
|
29
|
+
const total = items.reduce((sum, i) => sum + i.price * i.qty, 0);
|
|
30
|
+
return <span>{formatMoney(total)}</span>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Bad: derived state stored separately
|
|
34
|
+
function Cart({ items }: { items: CartItem[] }) {
|
|
35
|
+
const [total, setTotal] = useState(0);
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
setTotal(items.reduce((sum, i) => sum + i.price * i.qty, 0));
|
|
38
|
+
}, [items]);
|
|
39
|
+
return <span>{formatMoney(total)}</span>;
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Derived state in `useEffect` adds a render cycle, can desync, and obscures the data flow.
|
|
44
|
+
|
|
45
|
+
### 2. Side Effects Outside Render
|
|
46
|
+
|
|
47
|
+
Effects, mutations, network calls, and subscriptions live in event handlers or `useEffect` — never in the render body.
|
|
48
|
+
|
|
49
|
+
### 3. Composition Over Inheritance
|
|
50
|
+
|
|
51
|
+
React has no inheritance model for components. Compose with `children`, render props, or component props.
|
|
52
|
+
|
|
53
|
+
## Hooks Discipline
|
|
54
|
+
|
|
55
|
+
See [rules/react/hooks.md](../../rules/react/hooks.md) for the full ruleset. Highlights:
|
|
56
|
+
|
|
57
|
+
- Top-level only, never conditional
|
|
58
|
+
- Cleanup every subscription, interval, listener
|
|
59
|
+
- Functional updater (`setX(prev => prev + 1)`) when new state depends on old
|
|
60
|
+
- Default position: do not memoize — add `useMemo`/`useCallback` only when a profiler or a dependency chain proves it matters
|
|
61
|
+
- Extract a custom hook only when the same hook sequence appears in 2+ components
|
|
62
|
+
|
|
63
|
+
## State Location Decision Tree
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
Used by one component?
|
|
67
|
+
-> useState inside it
|
|
68
|
+
|
|
69
|
+
Used by parent + a few descendants?
|
|
70
|
+
-> lift to nearest common ancestor
|
|
71
|
+
|
|
72
|
+
Used across distant branches AND low-frequency reads (theme, auth, locale)?
|
|
73
|
+
-> React Context
|
|
74
|
+
|
|
75
|
+
High-frequency updates shared across the tree?
|
|
76
|
+
-> external store (Zustand, Jotai, Redux Toolkit)
|
|
77
|
+
|
|
78
|
+
Derived from a server?
|
|
79
|
+
-> server-state library (TanStack Query, SWR, RSC fetch)
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Most pages do not need context or a global store. Resist abstraction until duplicated lifting becomes painful.
|
|
83
|
+
|
|
84
|
+
## Server / Client Components (RSC)
|
|
85
|
+
|
|
86
|
+
```tsx
|
|
87
|
+
// Server Component - default, async, never ships JS for itself
|
|
88
|
+
export default async function ProductPage({ params }: { params: { id: string } }) {
|
|
89
|
+
const product = await db.product.findUnique({ where: { id: params.id } });
|
|
90
|
+
if (!product) notFound();
|
|
91
|
+
return <ProductView product={product} />;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Client Component - opt in with "use client"
|
|
95
|
+
"use client";
|
|
96
|
+
export function AddToCartButton({ productId }: { productId: string }) {
|
|
97
|
+
const [pending, startTransition] = useTransition();
|
|
98
|
+
return (
|
|
99
|
+
<button
|
|
100
|
+
disabled={pending}
|
|
101
|
+
onClick={() => startTransition(() => addToCart(productId))}
|
|
102
|
+
>
|
|
103
|
+
{pending ? "Adding..." : "Add to cart"}
|
|
104
|
+
</button>
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Boundaries:
|
|
110
|
+
|
|
111
|
+
- Server -> Client: pass serializable props or `children`
|
|
112
|
+
- Client -> Server: invoke Server Actions via `<form action={...}>` or imperatively from event handlers
|
|
113
|
+
- Never `import` a Server Component from a Client Component file — compose them via `children` instead
|
|
114
|
+
|
|
115
|
+
## Suspense + Error Boundaries
|
|
116
|
+
|
|
117
|
+
```tsx
|
|
118
|
+
<ErrorBoundary fallback={<ErrorView />}>
|
|
119
|
+
<Suspense fallback={<UserSkeleton />}>
|
|
120
|
+
<UserDetail id={id} />
|
|
121
|
+
</Suspense>
|
|
122
|
+
</ErrorBoundary>
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
- Place Suspense boundaries close to the data, not at the route root — progressively reveal content
|
|
126
|
+
- Error Boundary remains a class API; use `react-error-boundary` for a hook-friendly wrapper
|
|
127
|
+
- A boundary catches errors thrown during render, lifecycle, and constructors of its children — NOT in event handlers or async code
|
|
128
|
+
|
|
129
|
+
## Forms
|
|
130
|
+
|
|
131
|
+
### React 19 form actions (preferred for new code)
|
|
132
|
+
|
|
133
|
+
```tsx
|
|
134
|
+
"use client";
|
|
135
|
+
import { useActionState } from "react";
|
|
136
|
+
|
|
137
|
+
const initial = { error: null as string | null };
|
|
138
|
+
|
|
139
|
+
async function updateUserAction(_prev: typeof initial, formData: FormData) {
|
|
140
|
+
"use server";
|
|
141
|
+
const parsed = UserSchema.safeParse(Object.fromEntries(formData));
|
|
142
|
+
if (!parsed.success) return { error: "Invalid input" };
|
|
143
|
+
await db.user.update({ where: { id: parsed.data.id }, data: parsed.data });
|
|
144
|
+
return { error: null };
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export function UserForm() {
|
|
148
|
+
const [state, formAction, pending] = useActionState(updateUserAction, initial);
|
|
149
|
+
return (
|
|
150
|
+
<form action={formAction}>
|
|
151
|
+
<input name="name" required />
|
|
152
|
+
<button type="submit" disabled={pending}>Save</button>
|
|
153
|
+
{state.error && <p role="alert">{state.error}</p>}
|
|
154
|
+
</form>
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### Controlled inputs
|
|
160
|
+
|
|
161
|
+
Use controlled when the value drives other UI, formats on every keystroke, or implements real-time validation.
|
|
162
|
+
|
|
163
|
+
### Complex forms
|
|
164
|
+
|
|
165
|
+
For multi-step forms, dynamic field arrays, or cross-field validation: use a library (React Hook Form, TanStack Form). Roll-your-own state management for forms past trivial complexity is a maintenance trap.
|
|
166
|
+
|
|
167
|
+
## Data Fetching Decision Matrix
|
|
168
|
+
|
|
169
|
+
| Need | Tool |
|
|
170
|
+
|---|---|
|
|
171
|
+
| Per-request data in Next.js App Router | RSC `await fetch()` |
|
|
172
|
+
| Client-side cache + mutations + invalidation | TanStack Query |
|
|
173
|
+
| Lightweight client cache + revalidation | SWR |
|
|
174
|
+
| Real-time subscriptions | Server-Sent Events, WebSockets, or the lib's subscription API |
|
|
175
|
+
| One-off fire-and-forget | `fetch()` in an event handler |
|
|
176
|
+
|
|
177
|
+
Avoid `useEffect` + `fetch` for application data — race conditions, no cache, no retry, no Suspense integration.
|
|
178
|
+
|
|
179
|
+
## Composition Recipes
|
|
180
|
+
|
|
181
|
+
### Slot via `children`
|
|
182
|
+
|
|
183
|
+
```tsx
|
|
184
|
+
<Layout>
|
|
185
|
+
<Header />
|
|
186
|
+
<Main>{content}</Main>
|
|
187
|
+
</Layout>
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### Named slots
|
|
191
|
+
|
|
192
|
+
```tsx
|
|
193
|
+
<Page header={<Nav />} sidebar={<Filters />}>
|
|
194
|
+
<Results />
|
|
195
|
+
</Page>
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### Compound components (shared state via Context)
|
|
199
|
+
|
|
200
|
+
```tsx
|
|
201
|
+
<Tabs defaultValue="profile">
|
|
202
|
+
<Tabs.List>
|
|
203
|
+
<Tabs.Trigger value="profile">Profile</Tabs.Trigger>
|
|
204
|
+
<Tabs.Trigger value="settings">Settings</Tabs.Trigger>
|
|
205
|
+
</Tabs.List>
|
|
206
|
+
<Tabs.Panel value="profile"><Profile /></Tabs.Panel>
|
|
207
|
+
<Tabs.Panel value="settings"><Settings /></Tabs.Panel>
|
|
208
|
+
</Tabs>
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### Render prop / function-as-child
|
|
212
|
+
|
|
213
|
+
Useful when the parent needs to pass parameters to the rendered output:
|
|
214
|
+
|
|
215
|
+
```tsx
|
|
216
|
+
<DataLoader id={id}>
|
|
217
|
+
{({ data, isLoading }) => isLoading ? <Spinner /> : <UserCard user={data} />}
|
|
218
|
+
</DataLoader>
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
Modern alternative: a hook (`useData(id)`) returning the same shape — usually cleaner.
|
|
222
|
+
|
|
223
|
+
## Performance
|
|
224
|
+
|
|
225
|
+
### When `React.memo` Actually Helps
|
|
226
|
+
|
|
227
|
+
Wrap a component in `React.memo` only when:
|
|
228
|
+
|
|
229
|
+
1. It re-renders frequently
|
|
230
|
+
2. Its props are usually the same between renders
|
|
231
|
+
3. Its render is measurably expensive
|
|
232
|
+
|
|
233
|
+
`React.memo` adds an equality check on every render. If props differ on most renders, the check is pure overhead.
|
|
234
|
+
|
|
235
|
+
### Avoiding Render Cascades
|
|
236
|
+
|
|
237
|
+
- Lift state down rather than up where possible
|
|
238
|
+
- Split context: one context per concern, so a change to `themeContext` does not re-render auth consumers
|
|
239
|
+
- Use `useSyncExternalStore` for external state libraries — required for safe concurrent rendering
|
|
240
|
+
|
|
241
|
+
### Lists
|
|
242
|
+
|
|
243
|
+
- Provide stable `key` props (database id, not array index)
|
|
244
|
+
- Virtualize long lists with `@tanstack/react-virtual` or `react-window` once visible item count exceeds ~50 with non-trivial rows
|
|
245
|
+
|
|
246
|
+
## Accessibility-First Composition
|
|
247
|
+
|
|
248
|
+
- Always render semantic HTML (`<button>`, `<a>`, `<nav>`, `<main>`) before reaching for `role` attributes
|
|
249
|
+
- Every interactive element must be reachable by keyboard
|
|
250
|
+
- Form inputs need labels — `<label htmlFor>` or `aria-label` if visually labeled by an icon
|
|
251
|
+
- Manage focus on route changes and modal open/close
|
|
252
|
+
- Run `axe` in component tests (see [skills/react-testing](../react-testing/SKILL.md))
|
|
253
|
+
- Cross-link: [skills/accessibility/SKILL.md](../accessibility/SKILL.md) covers WCAG criteria and pattern libraries
|
|
254
|
+
|
|
255
|
+
## Routing
|
|
256
|
+
|
|
257
|
+
This skill is router-agnostic. The patterns above work with React Router, TanStack Router, Next.js App Router, Remix Router. Router-specific patterns (loaders, actions, nested layouts) follow the router's documentation — those are framework concerns layered on top of React core.
|
|
258
|
+
|
|
259
|
+
## Out of Scope (Pointer Sections)
|
|
260
|
+
|
|
261
|
+
- **Next.js specifics**: App Router data loading, Route Handlers, Middleware, Parallel Routes — separate concern, use Next.js docs
|
|
262
|
+
- **React Native**: Platform-specific patterns differ enough to warrant a separate `react-native-patterns` skill (not present yet)
|
|
263
|
+
- **Remix**: Loader/action conventions overlap with RSC but follow Remix docs
|
|
264
|
+
|
|
265
|
+
## Related
|
|
266
|
+
|
|
267
|
+
- Rules: [rules/react/](../../rules/react/) — coding-style, hooks, patterns, security, testing
|
|
268
|
+
- Skills: [react-performance](../react-performance/SKILL.md) for the Vercel-derived performance ruleset, [frontend-patterns](../frontend-patterns/SKILL.md) for cross-framework UI concerns, [accessibility](../accessibility/SKILL.md), [angular-developer](../angular-developer/SKILL.md) for framework comparison
|
|
269
|
+
- Agents: `react-reviewer` for code review, `react-build-resolver` for build/bundler errors
|
|
270
|
+
- Commands: `/react-review`, `/react-build`, `/react-test`
|
|
271
|
+
|
|
272
|
+
## Examples
|
|
273
|
+
|
|
274
|
+
### Custom hook for debounced search
|
|
275
|
+
|
|
276
|
+
```tsx
|
|
277
|
+
function useDebounce<T>(value: T, delay = 300): T {
|
|
278
|
+
const [debounced, setDebounced] = useState(value);
|
|
279
|
+
useEffect(() => {
|
|
280
|
+
const id = setTimeout(() => setDebounced(value), delay);
|
|
281
|
+
return () => clearTimeout(id);
|
|
282
|
+
}, [value, delay]);
|
|
283
|
+
return debounced;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
function SearchBox() {
|
|
287
|
+
const [query, setQuery] = useState("");
|
|
288
|
+
const debounced = useDebounce(query, 300);
|
|
289
|
+
const { data } = useQuery({
|
|
290
|
+
queryKey: ["search", debounced],
|
|
291
|
+
queryFn: () => searchApi(debounced),
|
|
292
|
+
enabled: debounced.length > 0,
|
|
293
|
+
});
|
|
294
|
+
return (
|
|
295
|
+
<>
|
|
296
|
+
<input value={query} onChange={(e) => setQuery(e.target.value)} />
|
|
297
|
+
<Results items={data ?? []} />
|
|
298
|
+
</>
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
### Optimistic UI with React 19 `useOptimistic`
|
|
304
|
+
|
|
305
|
+
```tsx
|
|
306
|
+
"use client";
|
|
307
|
+
import { useOptimistic } from "react";
|
|
308
|
+
|
|
309
|
+
export function MessageList({ messages }: { messages: Message[] }) {
|
|
310
|
+
const [optimistic, addOptimistic] = useOptimistic(
|
|
311
|
+
messages,
|
|
312
|
+
(state, newMessage: Message) => [...state, newMessage],
|
|
313
|
+
);
|
|
314
|
+
|
|
315
|
+
async function send(formData: FormData) {
|
|
316
|
+
const text = String(formData.get("text"));
|
|
317
|
+
addOptimistic({ id: "pending", text, sender: "me" });
|
|
318
|
+
await saveMessage(text);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
return (
|
|
322
|
+
<>
|
|
323
|
+
<ul>{optimistic.map((m) => <li key={m.id}>{m.text}</li>)}</ul>
|
|
324
|
+
<form action={send}>
|
|
325
|
+
<input name="text" />
|
|
326
|
+
<button type="submit">Send</button>
|
|
327
|
+
</form>
|
|
328
|
+
</>
|
|
329
|
+
);
|
|
330
|
+
}
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
### Splitting context to avoid render cascades
|
|
334
|
+
|
|
335
|
+
```tsx
|
|
336
|
+
// Two contexts: one rarely changes, one frequently
|
|
337
|
+
const ThemeContext = createContext<Theme>("light");
|
|
338
|
+
const NotificationsContext = createContext<Notification[]>([]);
|
|
339
|
+
|
|
340
|
+
// A component that only consumes ThemeContext does NOT re-render when notifications change
|
|
341
|
+
```
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Affaan Mustafa
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Attribution
|
|
2
|
+
|
|
3
|
+
This skill is copied from Affaan Mustafa's public `affaan-m/ECC` repository.
|
|
4
|
+
|
|
5
|
+
- Source: https://github.com/affaan-m/ECC/tree/main/skills/react-performance
|
|
6
|
+
- Imported from commit: `0f84c0e2796703fbda87d577b2636351418c7442`
|
|
7
|
+
- Upstream skill name: `react-performance`
|
|
8
|
+
- License: MIT
|
|
9
|
+
- Copyright: Copyright (c) 2026 Affaan Mustafa
|
|
10
|
+
|
|
11
|
+
The skill body notes that its React performance guidance is adapted from Vercel Labs `react-best-practices` under MIT. The upstream ECC MIT license text is preserved in `LICENSE`.
|