Copilot instructions for React 19 TypeScript components that forward native props, use effects only for synchronization and are tested by role.
.github/instructions/github-copilot-react-guidelines.instructions.md. Downloaded files need to be placed in that repository path.---
applyTo: "**/*"
---
# React Component Instructions
Applies to: React components, hooks and component tests (`**/*.tsx`, `**/*.jsx`).
Version baseline: checked against React 19.2 and the current react.dev documentation. Read `package.json` first; on React 18, `ref` is not a regular prop and you need `forwardRef`.
## Components
- Write function components in TypeScript with a named `Props` interface; use union types for variants instead of free strings.
- One component per responsibility. Split a component when one part re-renders for reasons the rest does not care about, or when a part is reused.
- Native elements first: a clickable action is a `<button type="button">`, navigation is a link. Add ARIA only when no native element fits.
- Forward native props when wrapping a native element, so callers can pass `aria-*`, `type`, `ref` and handlers.
```tsx
import type { ComponentPropsWithRef } from 'react';
type Variant = 'primary' | 'secondary';
interface ButtonProps extends ComponentPropsWithRef<'button'> {
variant?: Variant;
}
export function Button({ variant = 'primary', type = 'button', className, ...rest }: ButtonProps) {
return (
<button
type={type}
className={['btn', `btn-${variant}`, className].filter(Boolean).join(' ')}
{...rest}
/>
);
}
```
In React 19, `ref` arrives as a normal prop, so this component needs no `forwardRef`.
## Hooks
- `useState` for local UI state; derive values during render instead of copying props into state.
- `useEffect` only to synchronize with something outside React (subscriptions, timers, non-React widgets). Do not use it to compute data or respond to events; do that in the event handler.
- List every reactive value an effect reads in its dependency array, and return a cleanup function when the effect subscribes or starts timers.
- `useMemo` and `useCallback` are for measured costs or referential stability that a dependency requires. If the project uses React Compiler, do not add them by hand.
- For form submissions, consider `useActionState` and `useFormStatus` before writing manual pending state.
- Call hooks only at the top level of components and custom hooks.
## Tests
- Use the runner already configured (Vitest or Jest) with React Testing Library.
- Query by role and accessible name (`getByRole('button', { name: /save/i })`), and drive interactions with `@testing-library/user-event`.
- Assert what the user sees or what a callback receives, not internal state or hook calls.
- Test custom hooks with `renderHook` from `@testing-library/react`; `@testing-library/react-hooks` is deprecated.
```tsx
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { expect, test, vi } from 'vitest';
import { Button } from './Button';
test('calls onClick when pressed', async () => {
const onClick = vi.fn();
render(<Button onClick={onClick}>Save</Button>);
await userEvent.click(screen.getByRole('button', { name: 'Save' }));
expect(onClick).toHaveBeenCalledTimes(1);
});
```
## Verify before finishing
Run these when they are available in the project:
- `npx tsc --noEmit`
- `npx eslint .`, with `eslint-plugin-react-hooks` enabled (`rules-of-hooks`, `exhaustive-deps`)
- the component tests (`npx vitest run` or `npx jest`)
Cursor rules for Tailwind CSS v4: automatic class sorting, mobile-first breakpoints, CVA variants with merging, class-based dark mode via @custom-variant, and CSS-first @theme configuration.
Cursor rules for React with TypeScript: typed function components, React 19 ref-as-prop, hooks discipline, state ownership, error boundaries and measured performance work.
CLAUDE.md rules for React 19 with TypeScript covering typed components, derived state, compiler-aware memoization, useId-based accessibility and review checks.
Copilot
frontend
Illustrative input and expected result. This example is a verification guide, not a recorded model run.
Content reviewed .
A React 19 + TypeScript app uses these instructions for Copilot while a developer asks for a reusable button and a test for it.
Create components/Button.tsx with primary and secondary variants that works inside forms and accepts aria attributes and a ref. Add a test that clicking it calls onClick.
Illustrative; not a recorded model run. A function component whose props extend ComponentPropsWithRef<'button'> with variant typed as 'primary' | 'secondary', defaulting type to 'button' and spreading remaining props (ref included, no forwardRef on React 19); a test using the configured runner, render, getByRole('button', { name: 'Save' }) and userEvent.click, asserting the callback was called once.GitHub Copilot reads repository-wide custom instructions from .github/copilot-instructions.md and path-specific instructions from .github/instructions/*.instructions.md files with an applyTo glob. Copilot can also use AGENTS.md files, where the nearest file in the directory tree takes precedence. Which file types are honored depends on the surface: VS Code, Visual Studio, JetBrains, Xcode, Eclipse and GitHub.com differ.
.github/instructions/github-copilot-react-guidelines.instructions.mdStarting point, not a tested configuration for your repository. Used for files matching applyTo on surfaces that support path-specific instructions. Review the instructions, adapt the file paths and run your project's existing checks.
---
applyTo: "**/*"
---
# React Component Instructions
Applies to: React components, hooks and component tests (`**/*.tsx`, `**/*.jsx`).
Version baseline: checked against React 19.2 and the current react.dev documentation. Read `package.json` first; on React 18, `ref` is not a regular prop and you need `forwardRef`.
## Components
- Write function components in TypeScript with a named `Props` interface; use union types for variants instead of free strings.
- One component per responsibility. Split a component when one part re-renders for reasons the rest does not care about, or when a part is reused.
- Native elements first: a clickable action is a `<button type="button">`, navigation is a link. Add ARIA only when no native element fits.
- Forward native props when wrapping a native element, so callers can pass `aria-*`, `type`, `ref` and handlers.
```tsx
import type { ComponentPropsWithRef } from 'react';
type Variant = 'primary' | 'secondary';
interface ButtonProps extends ComponentPropsWithRef<'button'> {
variant?: Variant;
}
export function Button({ variant = 'primary', type = 'button', className, ...rest }: ButtonProps) {
return (
<button
type={type}
className={['btn', `btn-${variant}`, className].filter(Boolean).join(' ')}
{...rest}
/>
);
}
```
In React 19, `ref` arrives as a normal prop, so this component needs no `forwardRef`.
## Hooks
- `useState` for local UI state; derive values during render instead of copying props into state.
- `useEffect` only to synchronize with something outside React (subscriptions, timers, non-React widgets). Do not use it to compute data or respond to events; do that in the event handler.
- List every reactive value an effect reads in its dependency array, and return a cleanup function when the effect subscribes or starts timers.
- `useMemo` and `useCallback` are for measured costs or referential stability that a dependency requires. If the project uses React Compiler, do not add them by hand.
- For form submissions, consider `useActionState` and `useFormStatus` before writing manual pending state.
- Call hooks only at the top level of components and custom hooks.
## Tests
- Use the runner already configured (Vitest or Jest) with React Testing Library.
- Query by role and accessible name (`getByRole('button', { name: /save/i })`), and drive interactions with `@testing-library/user-event`.
- Assert what the user sees or what a callback receives, not internal state or hook calls.
- Test custom hooks with `renderHook` from `@testing-library/react`; `@testing-library/react-hooks` is deprecated.
```tsx
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { expect, test, vi } from 'vitest';
import { Button } from './Button';
test('calls onClick when pressed', async () => {
const onClick = vi.fn();
render(<Button onClick={onClick}>Save</Button>);
await userEvent.click(screen.getByRole('button', { name: 'Save' }));
expect(onClick).toHaveBeenCalledTimes(1);
});
```
## Verify before finishing
Run these when they are available in the project:
- `npx tsc --noEmit`
- `npx eslint .`, with `eslint-plugin-react-hooks` enabled (`rules-of-hooks`, `exhaustive-deps`)
- the component tests (`npx vitest run` or `npx jest`)
Ask for a small change to one matching file. Check the tool's loaded context or instruction view, inspect the diff for the requested convention, and run the relevant build or test. A well-formatted file does not guarantee the model follows every instruction.
Instruction support differs by surface: VS Code supports repository-wide, path-specific and AGENTS.md instructions; Visual Studio supports repository-wide and path-specific; JetBrains and Xcode use .github/copilot-instructions.md. GitHub's documentation describes AGENTS.md files stored anywhere in the repository, with the nearest file in the directory tree taking precedence, or alternatively a single CLAUDE.md or GEMINI.md in the root. Support differs by surface; GitHub's IDE page lists AGENTS.md among the instruction types for VS Code.
Documentation checked 2026-11-05: GitHub Docs: Adding repository custom instructionsGitHub Docs: Repository instructions in your IDE
Cursor rules for Tailwind CSS v4: automatic class sorting, mobile-first breakpoints, CVA variants with merging, class-based dark mode via @custom-variant, and CSS-first @theme configuration.
Cursor rules for React with TypeScript: typed function components, React 19 ref-as-prop, hooks discipline, state ownership, error boundaries and measured performance work.
CLAUDE.md rules for React 19 with TypeScript covering typed components, derived state, compiler-aware memoization, useId-based accessibility and review checks.