Course contentsShow
← React
Lesson 985 of 2,39625. Custom HooksFree lesson

Naming for Clarity and Intent

Choose names that clearly communicate what the hook does and what it returns (useToggle vs useBoolean vs useFlag).

Naming for Clarity and Intent

You'll learn how to choose custom hook names that instantly communicate their purpose and return values.

Why Hook Names Matter

A custom hook's name is its interface. When someone reads useBoolean, useToggle, or useFlag, they form different expectations about what it does and returns. Poor naming creates confusion: you'll find yourself constantly checking the implementation or documentation to remember what [value, setValue] actually represents.

The goal is self-documenting code. A well-named hook tells you:

  • What problem it solves
  • What kind of value it returns
  • How you should use it

Clarity Over Brevity

Consider three names for the same hook:

useToggle suggests flipping between two states, probably boolean. You'd expect something like [isOn, toggle].

useBoolean emphasizes the data type. It's generic — could be any boolean state. You might expect [value, setValue, setTrue, setFalse].

useFlag implies a simple on/off indicator, often for UI states like "isOpen" or "isVisible."

Each name creates a different mental model. Choose based on intent: if your hook specifically manages toggling behavior, useToggle is clearest. If it's about managing any boolean with rich controls, useBoolean might fit better.

The Test: Read It Aloud

Try reading your component code aloud: "Use toggle for modal visibility" versus "Use boolean for modal visibility." Which sounds more natural? Which better describes what the code does rather than just the type?

Key Takeaway: Name custom hooks to reveal their purpose and behavior, not just their data type — useToggle beats useBoolean when toggling is the core intent, while useBoolean wins when you need a full boolean state manager with multiple setters.