Skip to main content
Using a Centralized Typography Component in React
Adopting effective naming conventions is crucial in software development for ensuring code clarity, maintainability, and ease of collaboration. This guide covers various aspects of naming, from file names to constants, providing guidelines for best practices.

CamelCase

Used for object keys, function names, React state variables, and more.

Object Naming

State object keys should be descriptive and follow camelCase. Good Practice:
Bad Practice:

Hook naming

Combine ‘use’, action, and resource for clarity. Good Practice:
Bad Practice:

Function Naming

Function names should clearly indicate their purpose and action. Good Practice:
Bad Practice:

PascalCase

Used for class names, constructor functions, and React component names.

Type Naming: UserProfile

Good Example:
Bad Example:

Interface Naming: UserSettings

Good Example:
Bad Example:

snake_case

Commonly used for database fields and table names.

Database Schema Naming

Tables Naming: Good Practice:
Bad Practice:
Table Fields Naming: Good Practice:
Bad Practice:

UPPER_CASE_SNAKE_CASE

Used for constants and environment variable names

Constants

Good Practice:
Bad Practice:

Environment Variables

Good Practice:
Bad Practice:

kebab-case

Used for CSS class names and URL slugs.

CSS Class Naming

Good Practice:
Bad Practice:

Other Naming Conventions ✨

Configuration Files

Configuration file names should indicate their purpose and the environment they’re used in. Good Practice:
Bad Practice:
Certainly! Let’s include examples for folder naming conventions as well. In software development, folder names are typically given in PascalCase or kebab-case, depending on the project’s convention. Here’s how I would incorporate this into the document:

Folder Naming

Folder names should be clear, consistent, and indicative of their contents. Depending on the project’s convention, PascalCase or kebab-case can be used.
Recommend using kebab-case for folder names.
PascalCase for Folder Naming Good Practice:
Bad Practice:
kebab-case for Folder Naming Good Practice:
Bad Practice:

File Naming Conventions

File naming conventions organize and simplify your code, making it easier for teams to navigate. This guide emphasizes best practices for naming React components and files such as hooks and utils. It also warns against common mistakes to keep your project clear and consistent. Component Files (JSX/TSX) | Good Practice ✅ React component files should be named using PascalCase.
| Bad Practice ❌ Avoid using snake_case, kebab-case, or inconsistent capitalization in component filenames.
Hooks/Utils/Other JS or TS Files For non-component files, you have the option between kebab-case and camelCase. The key is to maintain consistency throughout the project. Choose one style and stick with it. | Good Practice ✅
  • Using Kebab-Case
  • Using CamelCase
| Bad Practice ❌ Mixing naming conventions within the same project or using unconventional casing can lead to a cluttered and confusing codebase.

Recommendation 📌

Decide whether to use kebab-case or camelCase for naming hooks, utilities, types, and other similar files in your project. Do not mix these conventions within the same codebase. The choice may depend on team preferences, the specific needs of the project, or existing conventions in related projects. Remember, consistency is paramount.

Programming Case Styles Cheat Sheet📘

Quick Reference for Naming Conventions in Different Programming Scenarios

Conclusion

Adopting clear and consistent naming conventions enhances the overall quality of your codebase, making it more accessible and easier to maintain. By following these guidelines, you’ll foster a more efficient and collaborative development environment.