Skip to content

Instantly share code, notes, and snippets.

@muhammadardie
Created December 5, 2025 09:46
Show Gist options
  • Select an option

  • Save muhammadardie/44ee1f77e091a982ba023beed9540bf1 to your computer and use it in GitHub Desktop.

Select an option

Save muhammadardie/44ee1f77e091a982ba023beed9540bf1 to your computer and use it in GitHub Desktop.
React File Naming Conventions

πŸ“ File Naming Conventions

Components β†’ PascalCase

components/
β”œβ”€β”€ Button.jsx
β”œβ”€β”€ UserProfile.jsx
β”œβ”€β”€ DataTable.jsx
└── ProcurementStatusDetail/
    β”œβ”€β”€ index.js
    β”œβ”€β”€ InfoSection.jsx
    β”œβ”€β”€ TindakLanjutSection.jsx
    └── DocumentHistory.jsx

Why? Matches the component name exactly, makes it obvious it's a component.

Pages/Routes β†’ PascalCase (same as components)

pages/
β”œβ”€β”€ Home.jsx
β”œβ”€β”€ Login.jsx
β”œβ”€β”€ Dashboard.jsx
└── procurement/
    β”œβ”€β”€ ProcurementList.jsx
    └── ProcurementDetail.jsx

Why? Pages are just components, so follow the same convention.

Hooks β†’ camelCase

hooks/
β”œβ”€β”€ useAuth.js
β”œβ”€β”€ useProcurementDetail.js
β”œβ”€β”€ useDebounce.js
└── useLocalStorage.js

Why? Hooks are functions, and JS functions use camelCase.

Utilities/Helpers β†’ camelCase

utils/
β”œβ”€β”€ formatDate.js
β”œβ”€β”€ validation.js
β”œβ”€β”€ apiHelpers.js
└── stringHelpers.js

Why? These export functions, which use camelCase.

Constants β†’ camelCase or SCREAMING_SNAKE_CASE for file

constants/
β”œβ”€β”€ apiEndpoints.js
β”œβ”€β”€ routes.js
β”œβ”€β”€ appConfig.js
└── errorMessages.js

// Inside the file:
export const API_BASE_URL = 'https://api.example.com';
export const MAX_RETRY_ATTEMPTS = 3;

Why? File is camelCase, exported constants are SCREAMING_SNAKE_CASE.

Context β†’ PascalCase

context/
β”œβ”€β”€ AuthContext.jsx
β”œβ”€β”€ ThemeContext.jsx
└── UserContext.jsx

Types/Interfaces (TypeScript) β†’ camelCase or PascalCase

types/
β”œβ”€β”€ user.ts          // exports User, UserProfile types
β”œβ”€β”€ procurement.ts   // exports Procurement, ProcurementItem
└── api.ts

Styles β†’ Match component name or camelCase

styles/
β”œβ”€β”€ Button.module.css        // CSS Modules β†’ PascalCase
β”œβ”€β”€ UserProfile.module.scss
β”œβ”€β”€ global.css               // Global styles β†’ camelCase
└── variables.scss

API/Services β†’ camelCase

api/
β”œβ”€β”€ authApi.js
β”œβ”€β”€ procurementApi.js
└── userService.js

services/
β”œβ”€β”€ analyticsService.js
└── notificationService.js

Config Files β†’ camelCase or kebab-case

config/
β”œβ”€β”€ webpack.config.js
β”œβ”€β”€ jest.config.js
β”œβ”€β”€ apiConfig.js
└── app-config.js

🎯 Quick Reference Table

Type Convention Example
Components PascalCase UserProfile.jsx
Pages PascalCase Dashboard.jsx
Hooks camelCase useAuth.js
Utils camelCase formatDate.js
Constants camelCase apiEndpoints.js
Context PascalCase AuthContext.jsx
Services/API camelCase userService.js
Styles Match component Button.module.css
Types camelCase user.ts

🚫 Avoid These

❌ user-profile.jsx       (kebab-case components)
❌ User_Profile.jsx       (snake_case components)
❌ UseAuth.js             (PascalCase hooks)
❌ format-date.js         (kebab-case utils)
❌ API_ENDPOINTS.js       (SCREAMING_SNAKE_CASE files)

πŸ“ Special Cases

Index Files

components/
└── Button/
    β”œβ”€β”€ index.js          βœ… Always lowercase
    β”œβ”€β”€ Button.jsx
    └── Button.test.js

Test Files

βœ… Button.test.jsx
βœ… Button.spec.jsx
βœ… useAuth.test.js

Stories (Storybook)

βœ… Button.stories.jsx
βœ… UserProfile.stories.jsx

πŸ† Industry Standards

Most popular React projects follow these conventions:

  • Create React App β†’ PascalCase components
  • Next.js β†’ PascalCase pages/components
  • Airbnb Style Guide β†’ PascalCase components
  • React Official Docs β†’ PascalCase components

πŸ’‘ Pro Tips

  1. Be consistent - Pick one convention per category and stick to it
  2. Match exports - UserProfile.jsx should export UserProfile
  3. Folder names - Usually kebab-case or camelCase: user-profile/ or userProfile/
  4. One component per file - Makes naming straightforward
  5. Use ESLint - Enforce conventions automatically

The key is consistency across your team/project! 🎯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment