Leadline Architecture Design

Naming conventions

Case styles, props, state, handlers, and file naming for React and TypeScript in LAD-aligned codebases

LAD naming conventions

This page describes naming conventions for React and TypeScript code: components, hooks, props, handlers, and related identifiers. It complements structural rules in Quick start and patterns in the Design patterns guide.

EntityConventionExampleRationale
ComponentsPascalCaseUserProfile, ShoppingCartDistinguishes them from regular HTML elements.
Interfaces/TypesPascalCaseExampleItem, UserProfileMatches component and class naming; treats types as nominal entities.
Fileskebab-case or lowercaseuser-profile.js, my-component.tsxPrevents conflicts on case-insensitive file systems and improves readability. (Note: some projects use PascalCase for files to match the component name)
Functions/VariablescamelCasefetchUserData, userNameStandard JavaScript practice.
Custom HookscamelCase prefixed with useuseFetchData, useOnlineStatusRequired by React to enforce "Rules of Hooks".
ConstantsUPPER_SNAKE_CASEMAX_HEIGHT, API_KEYMakes constants easily identifiable as unchanging values.
PropscamelCaseimageSrc, isLoading, onRemoveFollows standard JavaScript attribute naming. Boolean props often use is or has prefixes (e.g., isVisible).
Event HandlerscamelCase with handle prefixhandleSubmit, handleClick, handleLogout, handleInputChangeUse the handle prefix and camelCase for event handlers to clearly indicate their purpose and ensure consistency in React naming.
Folderskebab-case or lowercaseuser-profile, utils, componentsEnhances readability and consistency with file paths.

Functions

Function names are case-sensitive and should start with a lowercase letter. Use camelCase for naming. Prefer meaningful names and typically use imperative verbs.

✔️ Good❌ Avoid
getUserDataUserData
fetchOrdersFetchOrders
// ✔️
const getUserData = () => {
  // function implementation
  return userData;
};

const fetchOrders = () => {
  // function implementation
  return orders;
};

// ❌
const UserData = () => {
  // function implementation
  return userData;
};

const FetchOrders = () => {
  // function implementation
  return orders;
};

Interfaces and types

TypeScript interfaces and type aliases should use PascalCase.

✔️ Good❌ Avoid
ExampleItemexampleItem
// ✔️
interface ExampleItem {
  id: number;
  name: string;
}

type UserProfile = {
  id: string;
  email: string;
};

// ❌
interface exampleItem {
  id: number;
  name: string;
}

State variables

For boolean state variables, prefix them with is, has, or should.

✔️ Good❌ Avoid
isActive, setIsActiveactive, setActive
hasError, setHasErrorerror, setError
shouldRender, setShouldRenderrender, setRender
import { useState } from "react";

const ExampleComponent = () => {
  const [isActive, setIsActive] = useState(true); // ✔️
  const [hasError, setHasError] = useState(false); // ✔️
  const [shouldRender, setShouldRender] = useState(true); // ✔️

  // const [active, setActive] = useState(true); // ❌
  // const [error, setError] = useState(false); // ❌
  // const [render, setRender] = useState(true); // ❌

  const handleClick = () => {
    setIsActive(!isActive);
  };

  return (
    <div>
      {shouldRender && (
        <div className={isActive ? "active" : "inactive"}>
          <button onClick={handleClick}>{isActive ? "active" : "inactive"}</button>
          {hasError && <p>An error occurred.</p>}
        </div>
      )}
    </div>
  );
};

export default ExampleComponent;

By following this convention, the purpose and meaning of boolean state variables become clearer, making the code more readable and maintainable.


Prop types by value

TypeConventionExample
ArrayPlural nounsitems
NumberPrefix num or postfix count, indexnumItems, itemCount, itemIndex
BoolPrefix is, can, or has (see below)isVisible, canToggle, hasHeader
ObjectNounitem
NodePrefix nodecontainerNode
ElementPrefix elementhoverElement

Bool prefix usage

  • is — visual/behavior variations. e.g. isVisible, isEnabled, isActive
  • can — behavior or conditional visual variations. e.g. canToggle, canExpand, canHaveCancelButton
  • has — toggling UI elements. e.g. hasCancelButton, hasHeader

Name props to describe the component itself

Avoid naming props after the current user or environment.

❌ Avoid: naming after user or environment

WrongBetterReason
hasSubmitPermissionhasSubmitButtonDescribes permission, not the component
isMobileScreenisCompactLayoutDescribes viewport, not the layout variant
<MyForm hasSubmitButton={user.canSubmit} />
<MyForm isCompactLayout={browser.isMobileScreen} />

❌ Avoid: naming after children instead of the component

WrongBetter
onClickonItemClick
areCommentsLoadingisLoadingComments
hasIconisSpacious

When you want more room for content rather than toggling an icon, use isSpacious instead of hasIcon — the latter answers "why", not "what".

<MyList onItemClick={...} />

Event handler props

ConventionUse forExample
on prefixProp namesonSelect, onClick
handle prefixHandler functionshandleClick, handleChange
<MyComp onClick={this.handleClick} />

Tip: Avoid built-in event handler prop names for custom events. Use onSelect instead of onFocus or onClick when the native event is not of interest.

This page and links

Loading map…

On this page