October 2019
Intermediate to advanced
426 pages
11h 49m
English
As we have learned, the value is stored within the closure that is defined by the useState function. Every time the component rerenders, the closure is reinitialized, which means that our value will be reset. To solve this, we need to store the value in a global variable, outside of the function. That way, the value variable will be in the closure outside of the function, which means that when the function gets called again, the closure will not be reinitialized.
We can define a global variable as follows:
let valuefunction useState (initialState) {
if (typeof ...
Read now
Unlock full access