๐งพ Naming Conventions in React
Consistent naming improves readability, maintainability, and scalability. Below are standard naming practices followed in professional React projects.
๐ Folder & File Naming
- Folder Names: lowercase and kebab-case โ
components/, blog-posts/ - Component Files: PascalCase โ
Navbar.jsx, BlogCard.jsx - Hooks: camelCase with
useprefix โuseAuth.js - Stylesheets: Match component โ
Button.module.css - Tests: Match the component โ
Navbar.test.js
๐ค Component Naming
- Use PascalCase for all components โ
BlogCard,LoginForm - Always start functional components with an uppercase letter
โ๏ธ Variable & Function Naming
- camelCase for variables and functions โ
isLoggedIn, fetchUserData() - UPPER_CASE for constants โ
API_URL
๐ง State & Props Naming
- Name state clearly โ
isLoading, currentUser, postList - Props should be descriptive โ
onSubmit, isOpen, userData - Use
handleprefix for event handlers โhandleClick(),handleLogin()
๐ CSS Naming (if not using Tailwind)
- Use BEM or kebab-case โ
card-title,form-input--error - For CSS Modules, match the component โ
Button.module.css
โ Tips
- Be consistent across your app
- Use clear, meaningful names over short ones
- Avoid abbreviations unless common (e.g., API, URL)
- Prefix custom hooks with
useand context files withuseorThemeContext