c/agents › command
0votes

Cursor project rules for React + TypeScript

TemplateLow risk
submitted by CommandVault editors to c/agents

A .cursor/rules/*.mdc file that keeps Cursor's agent consistent with your React codebase.

Template · 7 variables
---
description: React + TypeScript conventions for {{project_name}}
globs: ["src/**/*.tsx", "src/**/*.ts"]
alwaysApply: false
---

# React + TypeScript rules

## Components
- Function components only. Props typed with an exported `type {{Component}}Props`.
- One component per file; file name matches the component.
- Keep components under ~150 lines; extract hooks for logic.

## State and data
- Local state first; lift only when two siblings need it.
- Data fetching through {{data_layer}}; never call fetch directly in components.
- No `any`. Use `unknown` and narrow.

## Styling
- {{styling_approach}} only. No inline style objects except for dynamic values.
- Use design tokens from `{{tokens_path}}`; never hard-code colors.

## Accessibility
- Every interactive element is a real button/link/input with a label.
- Images need meaningful alt text or alt="" when decorative.

## When you change code
- Update or add a test in `{{test_folder}}` for the behavior you changed.
- Run `{{lint_command}}` and fix what you introduced.
0 commentsreport

How to add this Cursor rule

  1. Fill in the 7 blanks above; Copy puts your answers into the file.
  2. Save it in .cursor/rules/ with the .mdc extension (plain .md files there are ignored), e.g. .cursor/rules/nextjs.mdc.
  3. The front matter decides when it applies: alwaysApply: true for every chat, globs for matching files, or a description so Cursor applies it when relevant.
  4. Check it in Cursor's Rules settings, then ask something about a matching file and confirm the answer follows the rule.
  • {{project_name}} Project name
  • {{Component}} Component
  • {{data_layer}} Data layer
  • {{styling_approach}} Styling approach
  • {{tokens_path}} Tokens path
  • {{test_folder}} Test folder
  • {{lint_command}} Lint command

Checked against Cursor docs: rules.

More from c/agents

See all of c/agents →
0 comments

Log in to join the discussion.