Consistent file naming helps keep your React codebase clean, organized, and easy to navigate. Here's a guide tailored for JavaScript-based React projects.
| File Type | Naming Convention | Example |
|---|---|---|
| Component | PascalCase | UserProfile.jsx |
| Hook | camelCase | useAuth.js |
| Service / API | kebab-case | auth-service.js |
| Utility / Helper | kebab-case | format-date.js |
| Page Component | PascalCase | DashboardPage.jsx |
| Stylesheets | kebab-case | user-profile.module.css |
| Context File | camelCase | authContext.js |
| Test File | Match target + .test.js |
UserProfile.test.js |
| PropTypes (optional) | kebab-case or colocated | user-prop-types.js or inline |
| General config | kebab-case | app-config.js or config.js |
| Environment config | dot + kebab-case | .env, .env.local, .env.production |
| Build config (Vite/Webpack) | kebab-case | vite.config.js, webpack.config.js |
| Linting config | dotfile or kebab | .eslintrc.js, eslint.config.js |
| Formatter config | dotfile | .prettierrc, .prettierrc.js |
| Jest config | kebab-case or default | jest.config.mjs |
| Babel config | dotfile or kebab | babel.config.cjs, .babelrc |
| TS Config (if used) | kebab-case | tsconfig.json |
src/
βββ components/
β βββ UserCard/
β β βββ UserCard.jsx
β β βββ user-card.module.css
β β βββ UserCard.test.js
βββ pages/
β βββ HomePage.jsx
β βββ DashboardPage.jsx
βββ hooks/
β βββ useAuth.js
β βββ useFetch.js
βββ services/
β βββ auth-service.js
β βββ user-service.js
βββ utils/
β βββ format-date.js
β βββ validate-email.js
βββ context/
β βββ authContext.js
βββ App.jsxmy-react-app/
βββ public/
βββ src/
βββ .env
βββ .gitignore
βββ package.json
βββ vite.config.js
βββ .eslintrc.js
βββ .prettierrc
βββ jest.config.mjs
βββ babel.config.cjs
βββ README.md- Use PascalCase for React components (matches JSX syntax:
<UserProfile />) - Use camelCase for hooks and context files (
useAuth.js,authContext.js) - Use kebab-case for services, utilities, and styles (
auth-service.js,format-date.js) - Keep test files next to the file they test (
Component.test.js)
- Be consistent across your team or project.
- Use folders like
components/,hooks/,services/,utils/, etc. for better separation of concerns. - You can colocate related files (styles, tests) with components inside their own folder.