Skip to content

Latest commit

Β 

History

History
92 lines (74 loc) Β· 3.61 KB

File metadata and controls

92 lines (74 loc) Β· 3.61 KB

🧾 React File Naming Conventions (JavaScript Version)

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 Naming by Type

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

πŸ—‚ Suggested src Folder Structure

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.jsx

πŸ—‚ Suggested react Folder Structure

my-react-app/
β”œβ”€β”€ public/
β”œβ”€β”€ src/
β”œβ”€β”€ .env
β”œβ”€β”€ .gitignore
β”œβ”€β”€ package.json
β”œβ”€β”€ vite.config.js
β”œβ”€β”€ .eslintrc.js
β”œβ”€β”€ .prettierrc
β”œβ”€β”€ jest.config.mjs
β”œβ”€β”€ babel.config.cjs
└── README.md

🧠 Quick Rules

  • 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)

βœ… Tips

  • 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.