Custom Hook Naming Conventions

📝 What Are Custom Hook Naming Conventions?

A Custom Hook is simply a JavaScript function that follows React's Hook conventions. One of the most important conventions is its name. Every custom Hook must begin with the word use, making it immediately recognizable as a Hook to both React and other developers.

Important

React relies on the use prefix to identify Hook functions. Following this convention also enables the React Hooks ESLint plugin to validate the Rules of Hooks.

🎯 Why Naming Conventions Matter

Consistent naming improves readability, makes code easier to maintain, and clearly communicates that a function contains Hook logic. Developers can instantly recognize that the function manages state, effects, or other React behavior.

  • Clearly identifies custom Hooks.
  • Supports the Rules of Hooks.
  • Improves code readability.
  • Makes reusable logic easier to discover.

📋 Basic Naming Rules

RuleDescription
Start with useEvery custom Hook name must begin with use.
Use Pascal-style suffixesCombine use with a descriptive name such as useCounter.
Be descriptiveThe name should explain the Hook's responsibility.
One responsibilityName the Hook after its primary purpose.

🔄 Naming Process

Identify the Hook's Purpose
Choose a Clear Name
Prefix the Name with use
Keep the Name Focused
Reuse the Hook Across Components

💻 Example 1: Correct Naming

Well-Named Custom Hooks

function useCounter() {
  // Counter logic
}

function useWindowSize() {
  // Window size logic
}

function useOnlineStatus() {
  // Network status logic
}

Each Hook starts with use and clearly describes the logic it provides.

💻 Example 2: Incorrect Naming

Poor Hook Names

function counter() {
  // ❌ Missing "use" prefix
}

function getWindowSize() {
  // ❌ Looks like a utility function
}

function helper() {
  // ❌ Name provides no meaning
}

These functions do not follow React's naming convention and may confuse developers or violate the Rules of Hooks.

💻 Example 3: Descriptive Hook Names

Meaningful Naming

function useTheme() {}

function useLocalStorage() {}

function useFetch() {}

function useAuth() {}

function useFormValidation() {}

Good Hook names immediately communicate their purpose without requiring developers to inspect their implementation.

📊 Good Names vs Poor Names

Good NamesPoor Names
useCountercounter
useWindowSizewindow
useThemethemeHelper
useOnlineStatusstatus

📅 Naming Workflow

🎯 Common Naming Patterns

Examples include useCounter, useToggle, and useTheme.

Examples include useWindowSize, useGeolocation, and useOnlineStatus.

Examples include useFetch, useUser, and useProducts.

Examples include useLocalStorage, useDebounce, and useClipboard.

⚠️ Common Mistakes

  • Omitting the use prefix.
  • Using vague names such as helper or utils.
  • Naming Hooks after multiple unrelated responsibilities.
  • Using names that resemble ordinary utility functions.

Warning

If a function calls React Hooks internally, its name should begin with use. This helps React tooling recognize it as a custom Hook.

✅ Best Practices

  • Always begin custom Hook names with use.
  • Choose names that describe the Hook's primary responsibility.
  • Keep Hook names concise and meaningful.
  • Follow consistent naming patterns throughout the project.
  • Avoid abbreviations unless they are widely understood.

📚 Official Resource

Learn more about custom Hook naming and the Rules of Hooks in the official React documentation at Reusing Logic with Custom Hooks.

Summary

Following consistent naming conventions makes custom Hooks easier to identify, understand, and reuse. Every custom Hook should begin with use and have a clear, descriptive, and single-purpose name, helping both developers and React tooling recognize it as a Hook.