๐งพ 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
use
prefix โ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
handle
prefix 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
use
and context files withuse
orThemeContext