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

The useState Signature: [value, setter] Array

Exploring the return value of useState and why it returns an array instead of an object.

The useState Signature: [value, setter] Array

What you'll learn: Why useState returns an array with exactly two elements, and how this design helps you name things flexibly.


When you call useState, it returns an array with two elements: the current state value at index 0, and the setter function at index 1.

const result = useState(0);
// result is [0, function]

Why an Array Instead of an Object?

React chose an array specifically to give you naming flexibility. With array destructuring, you can name both elements whatever makes sense for your state:

const [count, setCount] = useState(0);
const [name, setName] = useState('');
const [isOpen, setIsOpen] = useState(false);

If useState returned an object like { value: 0, setter: function }, you'd need to rename on every destructure:

// Hypothetical object return (NOT how React works):
const { value: count, setter: setCount } = useState(0);
const { value: name, setter: setName } = useState('');
// Tedious and verbose!

The Convention: [thing, setThing]

Because the array always has the same structure—value first, setter second—you can rely on position. The community convention is to name the setter set + capitalized state name, but this is just convention, not enforced:

const [user, updateUser] = useState(null); // Works fine

Key Takeaway: useState returns a two-element array [currentValue, setterFunction] to let you name your state variables anything you want using array destructuring, while always maintaining the same predictable order.