react
Installation
SKILL.md
Purpose
This skill defines how to write and structure React components so that code is type-safe, readable, and consistent across Alpha's projects. All rules here extend and respect the TypeScript skill — read skills/typescript/SKILL.md and its references first.
General Principles
- Extend the TypeScript skill: every rule from
skills/typescript/SKILL.mdapplies to React files unless explicitly overridden here. - Feature-based structure: organise code by domain area under
src/features/<feature>/. Each feature contains four sub-folders —components/(pure presentational),hooks/(shared hooks used by two or more consumers),utils/(pure helpers), andwidgets/(smart containers that wire hooks into components). A hook used by only one component or widget is co-located with that file, not placed inhooks/. Shared components used across features live insrc/components/. - Function declarations for components: always define components with the
functionkeyword, never as arrow function constants assigned to a variable. - Named exports only: always export components with
export function.export defaultis only allowed in framework router files that require it (Next.js page/layout files, TanStack Start route files). - Explicit JSX return type: every component must declare at least
JSX.Elementas its return type. UseJSX.Element | nullwhen the component can render nothing. - Named imports only: import React APIs by name. Never use
import * as React from 'react'or rely on a global React namespace. - Props interface naming: the props interface for a component named
Foomust be namedIFooProps.