3 ms·
> Also, that loading boolean seems unusually variable for a constant. Like any other constant, it never changes during the lifetime of its scope (a single func
by dragonwriter 5y ago
> Also, that loading boolean seems unusually variable for a constant.
Like any other constant, it never changes during the lifetime of its scope (a single function invocation) but can be different during different invocations. (The initialization by the useState function, though, is somewhat magical, involving external knowledge of whether this
invocation is rendering a new instance or rerendering an existing one.)
- ptx 5y agoSo where the article says loading // true setLoading(false) loading // false they mean that it will become false in the next invocation of the render function, I hope?
- dragonwriter 5y agoThat's exactly what the setter function returned by useState does, it sets the value returned the next time the corresponding useState is run for the same component (it is order based, which is why hooks must be run in a constant order.)