3 ms·
The developer isn't just "expected to know", because they'll get an error if they don't. React's debugger is really good at pointing out mistakes. As someone w
by grandpoobah 5y ago
The developer isn't just "expected to know", because they'll get an error if they don't. React's debugger is really good at pointing out mistakes.
As someone who started off thinking hooks were too "magic" to be taken seriously, such concerns are a thing of the past.
If you just think of calls to useState as variable declarations, it makes zero sense that you'd ever want to call useState in a different order.
this -
let userName = 'bob';
let favouriteColour = 'purple';
is this
let [ userName, setUserName ] = useState('bob)';
let [ favouriteColour , setFavouriteColour ] = useState('purple)';
Hooks enable you to reason about the state your component is in in a way that class components couldn't.
Hooks felt extremely awkward to me at first, because it was forcing me to write code in ways that felt unnatural. Once I stopped fighting it, the benefits became apparent, and now the old way feels awkward.
Hooks are to React what React was to jQuery.