agentleFS
PostHogKnown publisherPostHog/wizard-workbench/apps/basic-integration/react-router/saas-template/.cursor/rules/jsx-and-tsx.mdc

wizard-workbench / rules

Cursor rule5 starsChanged 6 months agoMITView on GitHub

When writing React code, use this guide for React best practices and guidance

We split this jsx-and-tsx.mdc into the rules it gives an agent

10 rules. About 0 are common, 9 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈9

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use ShadCN/ui for components.

    line 25
  2. Very specific:

    Use clear, descriptive, consistent naming.

    line 31
  3. Distinctive:

    Use proper React TypeScript types: MouseEventHandler<HTMLButtonElement>, ChangeEventHandler<HTMLInputElement>, ReactNode, React.Ref<T>, …

    line 37
  4. Distinctive:

    When extending HTML elements or existing components, use ComponentProps to inherit their props: ComponentProps<'input'>, …

    line 38
  5. Distinctive:

    When using server/database return types: Awaited<ReturnType<typeof serverFunction>>, wrap with NonNullable<> if guaranteed to exist.

    line 44
  6. Distinctive:

    Use consistent naming: isSubmitting = false, isLoading{Action} = false, is{Action}ing{Entity} = false

    line 54
  7. Distinctive:

    Always provide default values in function signature

    line 55
  8. Distinctive:

    Use FormProvider for parent, useFormContext for nested components

    line 60
  9. Distinctive:

    Use useTranslation with namespace and keyPrefix: const { t } = useTranslation('namespace', { keyPrefix: 'section' }).

    line 72
  10. Distinctive:

    Use Trans component for interpolation with links/components.

    line 73

≈ “Common” is an estimate: at least 1 in 5 of the 6,350 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
jsx-and-tsx.mdc
---
description: When writing React code, use this guide for React best practices and guidance
globs: **/*.js,**/*.jsx,**/*.tsx
alwaysApply: false
---

# React guide

Act as a top-tier software engineer with extensive React ecosystem knowledge to build high-quality fullstack web applications.

## Before Writing Code

- Observe the project's relevant existing code.
- Conform to existing code style, patterns, and conventions unless directed otherwise. Note: these instructions count as "directed otherwise" unless the user explicitly overrides them.

## Principles

- Display/container component pattern
  - Split your component into display components, which are pure functions that map props to JSX, and container components, which are (optional) stateful components that wrap one display component.
  - Then compose them together in the parent or page/route component.

Constraints {
  Be concise.
  You're using React Router V7 (the successor to Remix).
  Use ShadCN/ui for components. If a component is missing, install it.
  Modularize by feature; one concern per file or component; prefer named exports.
  This project uses TailwindCSS V4, so you can use things like container queries and child selectors.
}

NamingConstraints {
  Use clear, descriptive, consistent naming.
  Components should be postfixed with `Component`.
  Props should be the component's name, postifxed with `ComponentProps`.
}

TypeConstraints {
  Use proper React TypeScript types: MouseEventHandler<HTMLButtonElement>, ChangeEventHandler<HTMLInputElement>, ReactNode, React.Ref<T>, ComponentProps<'element'>, etc. Never use generic () => void or (event: any) => void.
  When extending HTML elements or existing components, use ComponentProps to inherit their props: ComponentProps<'input'>, ComponentProps<'button'>, ComponentProps<typeof ExistingComponent>.
  This project uses Prisma. If a prop comes from a database entity, use the entities type for it, e.g.:
    - type UserMenuProps = Pick<UserAccount, 'id' | 'name' | 'email'> & {
        onLogout: MouseEventHandler<HTMLInputElement>;
        organizationName: Organization['name'];
      }
  When using server/database return types: Awaited<ReturnType<typeof serverFunction>>, wrap with NonNullable<> if guaranteed to exist.
}

FormConstraints {
  For react-hook-form + Zod forms:
    - Export schema types: export type Schema = z.infer<typeof schema>
    - Export error types: export type SchemaErrors = FieldErrors<Schema>
    - Optionally include intent field: intent: z.literal('actionName')
    - Pass translation keys (not translated strings) in validation error messages
  For loading/submission states:
    - Use consistent naming: isSubmitting = false, isLoading{Action} = false, is{Action}ing{Entity} = false
    - Always provide default values in function signature
    - Disable forms with fieldset disabled={isSubmitting || isLoading} instead of individual disabled props
  For form components:
    - Accept errors?: SchemaErrors (always optional)
    - Accept children?: ReactNode for composition
    - Use FormProvider for parent, useFormContext for nested components
    - Provide complete defaultValues object to useForm with all fields initialized
}

AccessibilityConstraints {
  For interactive components, provide aria props with defaults:
    - *AriaLabel props for screen readers (e.g., countryAriaLabel = 'Select country')
    - *Placeholder props for empty states
    - FormControl handles aria-describedby and aria-invalid automatically
}

InternationalizationConstraints {
  Use useTranslation with namespace and keyPrefix: const { t } = useTranslation('namespace', { keyPrefix: 'section' });
  Use Trans component for interpolation with links/components.
  FormMessage components handle translation of error keys automatically.
}

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

Reviews can't be read right now.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.