SmartCodingTips

๐Ÿงพ 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 with use or ThemeContext