Course contentsShow
← React
Lesson 335 of 2,39610. useState BasicsFree lesson

Naming Convention: [thing, setThing]

The standard naming pattern for state variables and their setters for readability.

Naming Convention: [thing, setThing]

You'll learn the standard pattern React developers use to name state variables and their setter functions for maximum clarity.

The Convention Explained

When you use useState, you get back two values in an array: the current state value and a function to update it. The React community has adopted a universal naming pattern:

  • The state variable gets a descriptive name: count, isOpen, userName, items
  • The setter function gets that same name prefixed with "set": setCount, setIsOpen, setUserName, setItems

This pattern is so consistent that experienced React developers can instantly recognize what any piece of state code is doing:

const [count, setCount] = useState(0);
const [isVisible, setIsVisible] = useState(false);
const [email, setEmail] = useState('');
const [users, setUsers] = useState([]);

Why This Matters

Instant Recognition: When someone reads setCount(5), they immediately know this updates the count state variable. No guessing, no documentation needed.

Tooling Support: Many editor extensions and linters expect this pattern and provide better autocomplete and error detection when you follow it.

Team Consistency: Every React codebase uses this convention. It's like agreed-upon grammar rules—they make communication effortless.

You can name them differently (const [x, updateX] works technically), but you'd be fighting against the entire ecosystem. It's like spelling "color" as "culler"—people will understand, but it creates unnecessary friction.

Key Takeaway: Always name your state pairs as [thing, setThing]—it's the universal React convention that makes code instantly readable to any React developer.