Skip to content
Frameworks

React AGENTS.md

React changes go wrong when state moves to the wrong component or a new library arrives for one widget. This file tells the agent to keep state where the existing tree keeps it, to follow the hooks the file already uses, and to run the component tests.

Paste, then edit

Pair it with the TypeScript or JavaScript file if the repo has one. This page is about the UI tree, not the compiler.

In this stack

What to tell the agent

Do

  • Point at the test file pattern, such as Component.test.tsx beside the component.
  • Say whether styles are Tailwind classes or a CSS file imported by the component.
  • Name the design primitives (the button, the dialog) the agent should reuse.
  • Ask it to leave animation and marketing copy alone unless the task is visual.

Leave alone

  • Copying props into state and then forgetting to update them.
  • Adding useEffect to set state that could be computed during render.
  • Installing a component kit for a single control the app already has.
Starter file

AGENTS.md to copy

Save this as AGENTS.md at the root of the repository, or next to the package it covers. Replace the commands with the ones in this repo. See which agents read the file.

AGENTS.md
# React

## Components
- Follow the component style of the file you are in. Do not convert class components to functions unless that is the task.
- Keep state in the component that owns the interaction. Do not lift state through three parents for a single field.
- A custom hook is worth it when two components already share the logic. Do not extract a hook used once.

## Effects
- An effect synchronizes with something outside React. Derived values belong in render.
- Name the dependencies. Do not silence a missing dependency to keep an effect from running.

## Checks
- Run the component test script after a behavior change.
- Run the typecheck or lint script the package already has.
- If you add a visible string, say which screen shows it.

## Leave alone
- Do not add a state library, a CSS framework, or a router the app does not use.
- Do not rewrite a working component to a different pattern while fixing a bug in it.
Commands to confirm

Checks named in the file

Confirm each command exists here before you rely on it. Delete the ones this repository does not use.

  • Component tests. pnpm test
  • Lint. pnpm lint
FAQ

Questions

What is the React AGENTS.md for?

It keeps a React agent on the existing component patterns and the test command, without a new state library.

Should an agent introduce a state library for one React screen?

Use the state the tree already uses, usually component state or the project's existing store. A new library changes every future screen and is a separate decision.

Where should a React regression test live?

Next to the tests the package already has, covering the behavior that changed. A snapshot of the whole page is a weak check for a logic fix.

Keep going

Related on MCPpedia