I am teaching React in one of my courses, and I want to know what the most appropriate terminology is for React Hook’s useState. I have reviewed the documentation for React, and I don’t think they’re very clear about what to call specific constructs in the code.
const [state, setState] = useState(initialState);
What do you call state
, setState
, and useState
? Here’s what I’ve come up with talking to my colleagues:
useState
is the “Hook”. It tells React that you want to create a Stateful Value.setState
is the “Hook Setter”. It is certainly a Setter, although that is generic and vague. Internally, the React source code seems to refer to this as a “Dispatch” function. It can manipulate the Stateful Value.state
is the “Hook Accessor”. It is not a function, it is technically a constant (though a temporary one). It is not a value, since it is an identifier referencing a Stateful Value (in the same sense that a variable is not a value). Internally, they refer to this as “state”, but that seems quite generic.
What terminology does the community tend to use to differentiate the idea of the constant identifier holding the reference to the stateful value from the stateful value? Or is there some terminology that you individually use that can separate these ideas?