@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
|
@@ -0,0 +1,423 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: react-testing
|
|
3
|
+
description: React component testing with React Testing Library, Vitest/Jest, MSW for network mocking, accessibility assertions with axe, and the decision boundary between component tests and Playwright/Cypress end-to-end runs. Use when writing or fixing tests for React components, hooks, or pages.
|
|
4
|
+
origin: ECC
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# React Testing
|
|
8
|
+
|
|
9
|
+
Comprehensive React testing patterns for behavior-focused component tests, custom hook tests, accessibility assertions, and network-level mocking.
|
|
10
|
+
|
|
11
|
+
## When to Activate
|
|
12
|
+
|
|
13
|
+
- Writing tests for React components, custom hooks, or pages
|
|
14
|
+
- Adding test coverage to legacy untested components
|
|
15
|
+
- Migrating from Enzyme or class-component-era patterns to React Testing Library
|
|
16
|
+
- Setting up Vitest or Jest for a new React project
|
|
17
|
+
- Mocking HTTP requests in tests
|
|
18
|
+
- Asserting accessibility violations
|
|
19
|
+
- Deciding which tests belong in RTL vs Playwright Component Testing vs full E2E
|
|
20
|
+
|
|
21
|
+
## Core Principle
|
|
22
|
+
|
|
23
|
+
Test what the user sees and does, not implementation details.
|
|
24
|
+
|
|
25
|
+
A test should:
|
|
26
|
+
|
|
27
|
+
- Render the component with the same providers it has in production
|
|
28
|
+
- Interact with it via accessible queries (role, label) and `userEvent`
|
|
29
|
+
- Assert visible output and observable side effects (callback fired, request sent)
|
|
30
|
+
|
|
31
|
+
A test should NOT:
|
|
32
|
+
|
|
33
|
+
- Inspect component state, props passed to children, or which hooks were called
|
|
34
|
+
- Mock React itself or framework hooks
|
|
35
|
+
- Assert on the number of renders or DOM structure beyond what affects users
|
|
36
|
+
|
|
37
|
+
## Library Choice
|
|
38
|
+
|
|
39
|
+
| Runner | When | Note |
|
|
40
|
+
|---|---|---|
|
|
41
|
+
| **Vitest** | Vite, Remix, modern setups | Faster, native ESM, Jest-compatible API |
|
|
42
|
+
| **Jest** | Next.js, CRA, established repos | Default for many React projects |
|
|
43
|
+
| **Playwright Component Testing** | Real browser engine needed | Use when JSDOM lacks the required feature |
|
|
44
|
+
| **Cypress Component Testing** | Real browser, Cypress already in use | Alternative to Playwright CT |
|
|
45
|
+
|
|
46
|
+
Pick one. Do not run RTL + Vitest AND Playwright CT in the same repo unless you have a clear lane separation.
|
|
47
|
+
|
|
48
|
+
## Query Priority
|
|
49
|
+
|
|
50
|
+
React Testing Library exposes queries in three tiers — use top-down:
|
|
51
|
+
|
|
52
|
+
1. **Accessible to everyone**: `getByRole`, `getByLabelText`, `getByPlaceholderText`, `getByText`, `getByDisplayValue`
|
|
53
|
+
2. **Semantic**: `getByAltText`, `getByTitle`
|
|
54
|
+
3. **Test IDs (escape hatch)**: `getByTestId`
|
|
55
|
+
|
|
56
|
+
```tsx
|
|
57
|
+
// Best
|
|
58
|
+
screen.getByRole("button", { name: /save/i });
|
|
59
|
+
|
|
60
|
+
// OK for inputs
|
|
61
|
+
screen.getByLabelText("Email");
|
|
62
|
+
|
|
63
|
+
// Last resort
|
|
64
|
+
screen.getByTestId("save-btn");
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Variants:
|
|
68
|
+
|
|
69
|
+
- `getBy*` — throws if no match
|
|
70
|
+
- `queryBy*` — returns `null` (use for "assert absence")
|
|
71
|
+
- `findBy*` — async, returns a Promise (use for elements that appear after async work)
|
|
72
|
+
|
|
73
|
+
## User Interaction with `userEvent`
|
|
74
|
+
|
|
75
|
+
```tsx
|
|
76
|
+
import userEvent from "@testing-library/user-event";
|
|
77
|
+
|
|
78
|
+
test("submits the form", async () => {
|
|
79
|
+
const user = userEvent.setup();
|
|
80
|
+
const onSubmit = vi.fn();
|
|
81
|
+
render(<UserForm onSubmit={onSubmit} />);
|
|
82
|
+
|
|
83
|
+
await user.type(screen.getByLabelText("Email"), "user@example.com");
|
|
84
|
+
await user.click(screen.getByRole("button", { name: /save/i }));
|
|
85
|
+
|
|
86
|
+
expect(onSubmit).toHaveBeenCalledWith({ email: "user@example.com" });
|
|
87
|
+
});
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
- Always `await` userEvent calls
|
|
91
|
+
- Call `userEvent.setup()` once per test, reuse the returned `user`
|
|
92
|
+
- `userEvent` simulates a real browser sequence; `fireEvent` dispatches a single synthetic event — prefer `userEvent`
|
|
93
|
+
|
|
94
|
+
## Async Patterns
|
|
95
|
+
|
|
96
|
+
```tsx
|
|
97
|
+
// Element that appears after async work
|
|
98
|
+
expect(await screen.findByText("Loaded")).toBeInTheDocument();
|
|
99
|
+
|
|
100
|
+
// Side effect assertion
|
|
101
|
+
await waitFor(() => expect(saveSpy).toHaveBeenCalled());
|
|
102
|
+
|
|
103
|
+
// Element that should disappear
|
|
104
|
+
await waitForElementToBeRemoved(() => screen.queryByText("Loading"));
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Never `setTimeout` + assertion — flaky. Use the matchers above.
|
|
108
|
+
|
|
109
|
+
## Network Mocking with MSW
|
|
110
|
+
|
|
111
|
+
Mock Service Worker mocks at the network layer. The component, hooks, and fetch library all behave exactly as in production.
|
|
112
|
+
|
|
113
|
+
### Setup
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
// test/setup.ts
|
|
117
|
+
import { setupServer } from "msw/node";
|
|
118
|
+
import { http, HttpResponse } from "msw";
|
|
119
|
+
|
|
120
|
+
export const handlers = [
|
|
121
|
+
http.get("/api/users/:id", ({ params }) =>
|
|
122
|
+
HttpResponse.json({ id: params.id, name: "Alice" }),
|
|
123
|
+
),
|
|
124
|
+
http.post("/api/users", async ({ request }) => {
|
|
125
|
+
const body = await request.json();
|
|
126
|
+
return HttpResponse.json({ id: "new-id", ...body }, { status: 201 });
|
|
127
|
+
}),
|
|
128
|
+
];
|
|
129
|
+
|
|
130
|
+
export const server = setupServer(...handlers);
|
|
131
|
+
|
|
132
|
+
beforeAll(() => server.listen({ onUnhandledRequest: "error" }));
|
|
133
|
+
afterEach(() => server.resetHandlers());
|
|
134
|
+
afterAll(() => server.close());
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Configure `onUnhandledRequest: "error"` so any unmocked request fails the test loudly — silent passes are worse than red.
|
|
138
|
+
|
|
139
|
+
### Per-test override
|
|
140
|
+
|
|
141
|
+
```tsx
|
|
142
|
+
test("renders error on 500", async () => {
|
|
143
|
+
server.use(
|
|
144
|
+
http.get("/api/users/:id", () => new HttpResponse(null, { status: 500 })),
|
|
145
|
+
);
|
|
146
|
+
render(<UserPage id="1" />);
|
|
147
|
+
expect(await screen.findByText(/something went wrong/i)).toBeInTheDocument();
|
|
148
|
+
});
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## Provider Wrapping
|
|
152
|
+
|
|
153
|
+
Wrap providers once in a `test-utils.tsx`:
|
|
154
|
+
|
|
155
|
+
```tsx
|
|
156
|
+
// test-utils.tsx
|
|
157
|
+
import { render, RenderOptions } from "@testing-library/react";
|
|
158
|
+
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
159
|
+
|
|
160
|
+
export function renderWithProviders(
|
|
161
|
+
ui: React.ReactElement,
|
|
162
|
+
options?: RenderOptions,
|
|
163
|
+
) {
|
|
164
|
+
const queryClient = new QueryClient({
|
|
165
|
+
defaultOptions: { queries: { retry: false } },
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
return render(
|
|
169
|
+
<QueryClientProvider client={queryClient}>
|
|
170
|
+
<ThemeProvider theme={lightTheme}>
|
|
171
|
+
<MemoryRouter>{ui}</MemoryRouter>
|
|
172
|
+
</ThemeProvider>
|
|
173
|
+
</QueryClientProvider>,
|
|
174
|
+
options,
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export * from "@testing-library/react";
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
Then `import { renderWithProviders, screen } from "test-utils"` in every test file.
|
|
182
|
+
|
|
183
|
+
## Custom Hook Testing
|
|
184
|
+
|
|
185
|
+
```tsx
|
|
186
|
+
import { renderHook, act } from "@testing-library/react";
|
|
187
|
+
|
|
188
|
+
test("useCounter increments and decrements", () => {
|
|
189
|
+
const { result } = renderHook(() => useCounter(0));
|
|
190
|
+
|
|
191
|
+
expect(result.current.count).toBe(0);
|
|
192
|
+
|
|
193
|
+
act(() => result.current.increment());
|
|
194
|
+
expect(result.current.count).toBe(1);
|
|
195
|
+
|
|
196
|
+
act(() => result.current.decrement());
|
|
197
|
+
expect(result.current.count).toBe(0);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
test("useCounter accepts initial value", () => {
|
|
201
|
+
const { result } = renderHook(() => useCounter(10));
|
|
202
|
+
expect(result.current.count).toBe(10);
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
test("useUser fetches user data", async () => {
|
|
206
|
+
// Instantiate QueryClient ONCE per test outside the wrapper so it survives re-renders.
|
|
207
|
+
// Creating it inside the wrapper closure resets cache state on every render, producing flaky tests.
|
|
208
|
+
const queryClient = new QueryClient({
|
|
209
|
+
defaultOptions: { queries: { retry: false } },
|
|
210
|
+
});
|
|
211
|
+
const wrapper = ({ children }: { children: React.ReactNode }) => (
|
|
212
|
+
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
|
|
213
|
+
);
|
|
214
|
+
|
|
215
|
+
const { result } = renderHook(() => useUser("1"), { wrapper });
|
|
216
|
+
|
|
217
|
+
await waitFor(() => expect(result.current.isSuccess).toBe(true));
|
|
218
|
+
expect(result.current.data).toEqual({ id: "1", name: "Alice" });
|
|
219
|
+
});
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
- Wrap state-changing calls in `act`
|
|
223
|
+
- Test through the hook's public API only
|
|
224
|
+
- For hooks that use context, pass a `wrapper`
|
|
225
|
+
|
|
226
|
+
## Accessibility Assertions
|
|
227
|
+
|
|
228
|
+
```tsx
|
|
229
|
+
import { axe, toHaveNoViolations } from "jest-axe"; // or vitest-axe
|
|
230
|
+
expect.extend(toHaveNoViolations);
|
|
231
|
+
|
|
232
|
+
test("UserCard has no a11y violations", async () => {
|
|
233
|
+
const { container } = render(<UserCard user={mockUser} />);
|
|
234
|
+
expect(await axe(container)).toHaveNoViolations();
|
|
235
|
+
});
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
Run axe in component tests for every interactive component. Catches:
|
|
239
|
+
|
|
240
|
+
- Missing labels on form inputs
|
|
241
|
+
- Invalid ARIA usage
|
|
242
|
+
- Poor color contrast (limited — JSDOM has no real CSS engine, so this works for inline styles only; visual contrast belongs in Playwright)
|
|
243
|
+
- Missing alt text on images
|
|
244
|
+
- Heading order violations
|
|
245
|
+
|
|
246
|
+
Cross-link: [skills/accessibility/SKILL.md](../accessibility/SKILL.md) for the broader a11y testing playbook.
|
|
247
|
+
|
|
248
|
+
## When NOT to Use Snapshot Tests
|
|
249
|
+
|
|
250
|
+
Snapshots of rendered output:
|
|
251
|
+
|
|
252
|
+
- Break on every styling change
|
|
253
|
+
- Get rubber-stamped during review
|
|
254
|
+
- Test implementation detail (DOM structure), not behavior
|
|
255
|
+
|
|
256
|
+
Acceptable snapshot uses:
|
|
257
|
+
|
|
258
|
+
- Pure data serialization functions (`formatInvoice(invoice)` -> stable string)
|
|
259
|
+
- Generated config files (e.g., webpack config output)
|
|
260
|
+
|
|
261
|
+
For visual regression on components, use Playwright/Cypress screenshots or Percy/Chromatic — actual visual diffs, not DOM strings.
|
|
262
|
+
|
|
263
|
+
## When to Reach for Playwright / Cypress
|
|
264
|
+
|
|
265
|
+
JSDOM (used by Vitest/Jest) cannot:
|
|
266
|
+
|
|
267
|
+
- Render real layout (flexbox, grid, viewport queries)
|
|
268
|
+
- Run native browser animation, CSS transitions
|
|
269
|
+
- Test scrolling behavior, drag-and-drop, paste from clipboard
|
|
270
|
+
- Handle iframes, popups, downloads, cross-origin flows
|
|
271
|
+
- Run real network in a controlled environment with full DevTools support
|
|
272
|
+
|
|
273
|
+
For any of those, use Playwright Component Testing (component test in real browser) or full E2E. See [e2e-testing skill](../e2e-testing/SKILL.md).
|
|
274
|
+
|
|
275
|
+
Decision boundary:
|
|
276
|
+
|
|
277
|
+
- A hook, a presentational component, a form with logic -> RTL
|
|
278
|
+
- A component whose layout matters or that uses browser APIs not in JSDOM -> Playwright CT
|
|
279
|
+
- A full user flow across multiple pages -> Playwright/Cypress E2E
|
|
280
|
+
|
|
281
|
+
## Coverage Targets
|
|
282
|
+
|
|
283
|
+
| Layer | Target |
|
|
284
|
+
|---|---|
|
|
285
|
+
| Pure utilities | >=90% |
|
|
286
|
+
| Custom hooks | >=85% |
|
|
287
|
+
| Presentational components | >=80% — behavior, not lines |
|
|
288
|
+
| Container components | >=70% — golden paths + error states |
|
|
289
|
+
| Pages | E2E covered separately; smoke test minimum |
|
|
290
|
+
|
|
291
|
+
Configure via `vitest.config.ts` / `jest.config.js`:
|
|
292
|
+
|
|
293
|
+
```ts
|
|
294
|
+
// vitest.config.ts
|
|
295
|
+
test: {
|
|
296
|
+
coverage: {
|
|
297
|
+
provider: "v8",
|
|
298
|
+
reporter: ["text", "html", "lcov"],
|
|
299
|
+
thresholds: {
|
|
300
|
+
lines: 80,
|
|
301
|
+
functions: 80,
|
|
302
|
+
branches: 70,
|
|
303
|
+
statements: 80,
|
|
304
|
+
},
|
|
305
|
+
},
|
|
306
|
+
}
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
## Anti-Patterns
|
|
310
|
+
|
|
311
|
+
- `container.querySelector("...")` — bypasses accessibility queries, lets tests pass when real users would fail
|
|
312
|
+
- Asserting on number of renders — implementation detail
|
|
313
|
+
- `jest.mock("react", ...)` — never mock React. Refactor the component instead
|
|
314
|
+
- Mocking child components by default — tests the integration, not isolation. Mock only when the child has heavy side effects
|
|
315
|
+
- Ignoring `act()` warnings — they signal real bugs (state update after unmount, missing async wrapping)
|
|
316
|
+
- Sharing mutable state across tests — flakes when test order changes
|
|
317
|
+
- Tests that pass with `it.skip()` removed — your test does not actually assert what you think
|
|
318
|
+
|
|
319
|
+
## TDD Workflow
|
|
320
|
+
|
|
321
|
+
```
|
|
322
|
+
RED -> Write failing test for the next requirement
|
|
323
|
+
GREEN -> Write minimal component code to pass
|
|
324
|
+
REFACTOR -> Improve the component, tests stay green
|
|
325
|
+
REPEAT -> Next requirement
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
For new components:
|
|
329
|
+
|
|
330
|
+
1. Define the component's prop type and signature
|
|
331
|
+
2. Write the first test for the simplest case
|
|
332
|
+
3. Verify it fails for the right reason
|
|
333
|
+
4. Implement just enough to pass
|
|
334
|
+
5. Add the next test case
|
|
335
|
+
6. Refactor when the third similar test reveals a pattern
|
|
336
|
+
|
|
337
|
+
## Test Commands
|
|
338
|
+
|
|
339
|
+
```bash
|
|
340
|
+
# Vitest
|
|
341
|
+
vitest # watch
|
|
342
|
+
vitest run # one-shot
|
|
343
|
+
vitest run --coverage # with coverage
|
|
344
|
+
vitest run path/to/file.test.tsx # single file
|
|
345
|
+
|
|
346
|
+
# Jest
|
|
347
|
+
jest --watch
|
|
348
|
+
jest --coverage
|
|
349
|
+
jest path/to/file.test.tsx
|
|
350
|
+
|
|
351
|
+
# CI mode
|
|
352
|
+
CI=true vitest run --coverage
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
## Related
|
|
356
|
+
|
|
357
|
+
- Rules: [rules/react/testing.md](../../rules/react/testing.md)
|
|
358
|
+
- Skills: [react-patterns](../react-patterns/SKILL.md), [accessibility](../accessibility/SKILL.md), [e2e-testing](../e2e-testing/SKILL.md), [tdd-workflow](../tdd-workflow/SKILL.md)
|
|
359
|
+
- Agents: `react-reviewer` (reviews test quality during code review), `tdd-guide` (enforces TDD process)
|
|
360
|
+
- Commands: `/react-test`, `/react-review`
|
|
361
|
+
|
|
362
|
+
## Examples
|
|
363
|
+
|
|
364
|
+
### Form submission with MSW and userEvent
|
|
365
|
+
|
|
366
|
+
```tsx
|
|
367
|
+
test("submits user form and shows success", async () => {
|
|
368
|
+
server.use(
|
|
369
|
+
http.post("/api/users", () =>
|
|
370
|
+
HttpResponse.json({ id: "1", name: "Alice" }, { status: 201 }),
|
|
371
|
+
),
|
|
372
|
+
);
|
|
373
|
+
|
|
374
|
+
const user = userEvent.setup();
|
|
375
|
+
renderWithProviders(<UserForm />);
|
|
376
|
+
|
|
377
|
+
await user.type(screen.getByLabelText("Name"), "Alice");
|
|
378
|
+
await user.type(screen.getByLabelText("Email"), "alice@example.com");
|
|
379
|
+
await user.click(screen.getByRole("button", { name: /save/i }));
|
|
380
|
+
|
|
381
|
+
expect(await screen.findByText(/saved successfully/i)).toBeInTheDocument();
|
|
382
|
+
});
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
### Testing an error boundary
|
|
386
|
+
|
|
387
|
+
```tsx
|
|
388
|
+
function Broken() {
|
|
389
|
+
throw new Error("boom");
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
test("error boundary renders fallback", () => {
|
|
393
|
+
// Suppress React's console.error noise for the expected throw, then restore so
|
|
394
|
+
// the spy does not leak across tests and hide real errors elsewhere.
|
|
395
|
+
const errorSpy = vi.spyOn(console, "error").mockImplementation(() => {});
|
|
396
|
+
try {
|
|
397
|
+
render(
|
|
398
|
+
<ErrorBoundary fallback={<div>Something went wrong</div>}>
|
|
399
|
+
<Broken />
|
|
400
|
+
</ErrorBoundary>,
|
|
401
|
+
);
|
|
402
|
+
|
|
403
|
+
expect(screen.getByText("Something went wrong")).toBeInTheDocument();
|
|
404
|
+
} finally {
|
|
405
|
+
errorSpy.mockRestore();
|
|
406
|
+
}
|
|
407
|
+
});
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
### Testing a Suspense boundary
|
|
411
|
+
|
|
412
|
+
```tsx
|
|
413
|
+
test("shows loading then content", async () => {
|
|
414
|
+
renderWithProviders(
|
|
415
|
+
<Suspense fallback={<div>Loading...</div>}>
|
|
416
|
+
<UserDetail id="1" />
|
|
417
|
+
</Suspense>,
|
|
418
|
+
);
|
|
419
|
+
|
|
420
|
+
expect(screen.getByText("Loading...")).toBeInTheDocument();
|
|
421
|
+
expect(await screen.findByText("Alice")).toBeInTheDocument();
|
|
422
|
+
});
|
|
423
|
+
```
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025
|
|
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 Jeffallan's public `Jeffallan/claude-skills` repository.
|
|
4
|
+
|
|
5
|
+
- Source: https://github.com/Jeffallan/claude-skills/tree/main/skills/react-native-expert
|
|
6
|
+
- Imported from commit: `e8be415bc94d8d6ebddc2fb50e5d03c6e27d4319`
|
|
7
|
+
- Upstream skill name: `react-native-expert`
|
|
8
|
+
- License: MIT
|
|
9
|
+
- Copyright: Copyright (c) 2025
|
|
10
|
+
|
|
11
|
+
The upstream MIT license text is preserved in `LICENSE`.
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: react-native-expert
|
|
3
|
+
description: Builds, optimizes, and debugs cross-platform mobile applications with React Native and Expo. Implements navigation hierarchies (tabs, stacks, drawers), configures native modules, optimizes FlatList rendering with memo and useCallback, and handles platform-specific code for iOS and Android. Use when building a React Native or Expo mobile app, setting up navigation, integrating native modules, improving scroll performance, handling SafeArea or keyboard input, or configuring Expo SDK projects.
|
|
4
|
+
license: MIT
|
|
5
|
+
metadata:
|
|
6
|
+
author: https://github.com/Jeffallan
|
|
7
|
+
version: "1.1.0"
|
|
8
|
+
domain: frontend
|
|
9
|
+
triggers: React Native, Expo, mobile app, iOS, Android, cross-platform, native module
|
|
10
|
+
role: specialist
|
|
11
|
+
scope: implementation
|
|
12
|
+
output-format: code
|
|
13
|
+
related-skills: react-expert, flutter-expert, test-master
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
# React Native Expert
|
|
17
|
+
|
|
18
|
+
Senior mobile engineer building production-ready cross-platform applications with React Native and Expo.
|
|
19
|
+
|
|
20
|
+
## Core Workflow
|
|
21
|
+
|
|
22
|
+
1. **Setup** — Expo Router or React Navigation, TypeScript config → _run `npx expo doctor` to verify environment and SDK compatibility; fix any reported issues before proceeding_
|
|
23
|
+
2. **Structure** — Feature-based organization
|
|
24
|
+
3. **Implement** — Components with platform handling → _verify on iOS simulator and Android emulator; check Metro bundler output for errors before moving on_
|
|
25
|
+
4. **Optimize** — FlatList, images, memory → _profile with Flipper or React DevTools_
|
|
26
|
+
5. **Test** — Both platforms, real devices
|
|
27
|
+
|
|
28
|
+
### Error Recovery
|
|
29
|
+
- **Metro bundler errors** → clear cache with `npx expo start --clear`, then restart
|
|
30
|
+
- **iOS build fails** → check Xcode logs → resolve native dependency or provisioning issue → rebuild with `npx expo run:ios`
|
|
31
|
+
- **Android build fails** → check `adb logcat` or Gradle output → resolve SDK/NDK version mismatch → rebuild with `npx expo run:android`
|
|
32
|
+
- **Native module not found** → run `npx expo install <module>` to ensure compatible version, then rebuild native layers
|
|
33
|
+
|
|
34
|
+
## Reference Guide
|
|
35
|
+
|
|
36
|
+
Load detailed guidance based on context:
|
|
37
|
+
|
|
38
|
+
| Topic | Reference | Load When |
|
|
39
|
+
|-------|-----------|-----------|
|
|
40
|
+
| Navigation | `references/expo-router.md` | Expo Router, tabs, stacks, deep linking |
|
|
41
|
+
| Platform | `references/platform-handling.md` | iOS/Android code, SafeArea, keyboard |
|
|
42
|
+
| Lists | `references/list-optimization.md` | FlatList, performance, memo |
|
|
43
|
+
| Storage | `references/storage-hooks.md` | AsyncStorage, MMKV, persistence |
|
|
44
|
+
| Structure | `references/project-structure.md` | Project setup, architecture |
|
|
45
|
+
|
|
46
|
+
## Constraints
|
|
47
|
+
|
|
48
|
+
### MUST DO
|
|
49
|
+
- Use FlatList/SectionList for lists (not ScrollView)
|
|
50
|
+
- Implement memo + useCallback for list items
|
|
51
|
+
- Handle SafeAreaView for notches
|
|
52
|
+
- Test on both iOS and Android real devices
|
|
53
|
+
- Use KeyboardAvoidingView for forms
|
|
54
|
+
- Handle Android back button in navigation
|
|
55
|
+
|
|
56
|
+
### MUST NOT DO
|
|
57
|
+
- Use ScrollView for large lists
|
|
58
|
+
- Use inline styles extensively (creates new objects)
|
|
59
|
+
- Hardcode dimensions (use Dimensions API or flex)
|
|
60
|
+
- Ignore memory leaks from subscriptions
|
|
61
|
+
- Skip platform-specific testing
|
|
62
|
+
- Use waitFor/setTimeout for animations (use Reanimated)
|
|
63
|
+
|
|
64
|
+
## Code Examples
|
|
65
|
+
|
|
66
|
+
### Optimized FlatList with memo + useCallback
|
|
67
|
+
|
|
68
|
+
```tsx
|
|
69
|
+
import React, { memo, useCallback } from 'react';
|
|
70
|
+
import { FlatList, View, Text, StyleSheet } from 'react-native';
|
|
71
|
+
|
|
72
|
+
type Item = { id: string; title: string };
|
|
73
|
+
|
|
74
|
+
const ListItem = memo(({ title, onPress }: { title: string; onPress: () => void }) => (
|
|
75
|
+
<View style={styles.item}>
|
|
76
|
+
<Text onPress={onPress}>{title}</Text>
|
|
77
|
+
</View>
|
|
78
|
+
));
|
|
79
|
+
|
|
80
|
+
export function ItemList({ data }: { data: Item[] }) {
|
|
81
|
+
const handlePress = useCallback((id: string) => {
|
|
82
|
+
console.log('pressed', id);
|
|
83
|
+
}, []);
|
|
84
|
+
|
|
85
|
+
const renderItem = useCallback(
|
|
86
|
+
({ item }: { item: Item }) => (
|
|
87
|
+
<ListItem title={item.title} onPress={() => handlePress(item.id)} />
|
|
88
|
+
),
|
|
89
|
+
[handlePress]
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
return (
|
|
93
|
+
<FlatList
|
|
94
|
+
data={data}
|
|
95
|
+
keyExtractor={(item) => item.id}
|
|
96
|
+
renderItem={renderItem}
|
|
97
|
+
removeClippedSubviews
|
|
98
|
+
maxToRenderPerBatch={10}
|
|
99
|
+
windowSize={5}
|
|
100
|
+
/>
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const styles = StyleSheet.create({
|
|
105
|
+
item: { padding: 16, borderBottomWidth: StyleSheet.hairlineWidth },
|
|
106
|
+
});
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### KeyboardAvoidingView Form
|
|
110
|
+
|
|
111
|
+
```tsx
|
|
112
|
+
import React from 'react';
|
|
113
|
+
import {
|
|
114
|
+
KeyboardAvoidingView,
|
|
115
|
+
Platform,
|
|
116
|
+
ScrollView,
|
|
117
|
+
TextInput,
|
|
118
|
+
StyleSheet,
|
|
119
|
+
SafeAreaView,
|
|
120
|
+
} from 'react-native';
|
|
121
|
+
|
|
122
|
+
export function LoginForm() {
|
|
123
|
+
return (
|
|
124
|
+
<SafeAreaView style={styles.safe}>
|
|
125
|
+
<KeyboardAvoidingView
|
|
126
|
+
style={styles.flex}
|
|
127
|
+
behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
|
|
128
|
+
>
|
|
129
|
+
<ScrollView contentContainerStyle={styles.content} keyboardShouldPersistTaps="handled">
|
|
130
|
+
<TextInput style={styles.input} placeholder="Email" autoCapitalize="none" />
|
|
131
|
+
<TextInput style={styles.input} placeholder="Password" secureTextEntry />
|
|
132
|
+
</ScrollView>
|
|
133
|
+
</KeyboardAvoidingView>
|
|
134
|
+
</SafeAreaView>
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const styles = StyleSheet.create({
|
|
139
|
+
safe: { flex: 1 },
|
|
140
|
+
flex: { flex: 1 },
|
|
141
|
+
content: { padding: 16, gap: 12 },
|
|
142
|
+
input: { borderWidth: 1, borderRadius: 8, padding: 12, fontSize: 16 },
|
|
143
|
+
});
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### Platform-Specific Component
|
|
147
|
+
|
|
148
|
+
```tsx
|
|
149
|
+
import { Platform, StyleSheet, View, Text } from 'react-native';
|
|
150
|
+
|
|
151
|
+
export function StatusChip({ label }: { label: string }) {
|
|
152
|
+
return (
|
|
153
|
+
<View style={styles.chip}>
|
|
154
|
+
<Text style={styles.label}>{label}</Text>
|
|
155
|
+
</View>
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const styles = StyleSheet.create({
|
|
160
|
+
chip: {
|
|
161
|
+
paddingHorizontal: 12,
|
|
162
|
+
paddingVertical: 4,
|
|
163
|
+
borderRadius: 999,
|
|
164
|
+
backgroundColor: '#0a7ea4',
|
|
165
|
+
// Platform-specific shadow
|
|
166
|
+
...Platform.select({
|
|
167
|
+
ios: { shadowColor: '#000', shadowOffset: { width: 0, height: 2 }, shadowOpacity: 0.2, shadowRadius: 4 },
|
|
168
|
+
android: { elevation: 3 },
|
|
169
|
+
}),
|
|
170
|
+
},
|
|
171
|
+
label: { color: '#fff', fontSize: 13, fontWeight: '600' },
|
|
172
|
+
});
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## Output Format
|
|
176
|
+
|
|
177
|
+
When implementing React Native features, deliver:
|
|
178
|
+
1. **Component code** — TypeScript, with prop types defined
|
|
179
|
+
2. **Platform handling** — `Platform.select` or `.ios.tsx` / `.android.tsx` splits as needed
|
|
180
|
+
3. **Navigation integration** — route params typed, back-button handling included
|
|
181
|
+
4. **Performance notes** — memo boundaries, key extractor strategy, image caching
|
|
182
|
+
|
|
183
|
+
## Knowledge Reference
|
|
184
|
+
|
|
185
|
+
React Native 0.73+, Expo SDK 50+, Expo Router, React Navigation 7, Reanimated 3, Gesture Handler, AsyncStorage, MMKV, React Query, Zustand
|
|
186
|
+
|
|
187
|
+
[Documentation](https://jeffallan.github.io/claude-skills/skills/frontend/react-native-expert/)
|