- Always use explicit types for function arguments, return values, and variables.
- Avoid using
any. Useunknownor proper generics if type is uncertain. - Prefer interfaces over types for object shapes, especially for props and state.
- Use enums or union types for fixed sets of values.
- Use functional components and React hooks. Avoid class components unless necessary.
- Destructure props and state at the top of the component.
- Define prop types with TypeScript interfaces and use
React.FC<Props>. - Avoid inline functions in JSX; define handlers outside render.
- Memoize expensive computations and callbacks with
useMemoanduseCallback. - Use
useEffectdependencies correctly; never leave the dependency array empty unless intentional.
- Keep components small and focused; one component per file.
- Extract reusable logic into custom hooks or utility functions.
- Group related files (component, styles, tests) together.
- Use clear, descriptive names for variables, functions, and components.
- Remove dead code, commented-out code, and unused imports.
- Prefer local state for UI logic; use context or state libraries (Apollo) for shared/global state.
- Avoid prop drilling; use context or composition.
- Keep state minimal and normalized.
- Handle all async errors with try/catch or error boundaries.
- Validate all external data (API responses, user input).
- Provide fallback UI for loading and error states.
- Avoid unnecessary re-renders (memoize components, use keys correctly).
- Use lazy loading for heavy components and code splitting for routes.
- Avoid deep prop chains and large prop objects.
- Write unit tests for all logic-heavy functions and components.
- Use React Testing Library for component tests; avoid testing implementation details.
- Mock external dependencies and APIs.
- Use semantic HTML elements and ARIA attributes where needed.
- Ensure all interactive elements are keyboard accessible.
- Provide alt text for images and labels for form fields.
- Use CSS modules, styled-components, or emotion for scoped styles.
- Avoid global styles unless necessary.
- Prefer className over inline styles for maintainability.
- Follow project linting and formatting rules (Prettier, ESLint).
- Keep imports ordered and grouped (external, internal, styles).
- Use single quotes and trailing commas as per project conventions.
Review every PR for these points. Leave actionable, specific feedback.