Making a Value Persistent
Learn about the techniques and principles for ensuring the persistence of values within a state management system in a React application.
We'll cover the following
Persisting the value
JavaScript supports function scope, which means that variables defined inside a function cannot be accessed from outside the function. As a result, each function has its own scope. If we invoke a function multiple times, there'll be multiple scopes. However, no matter how many times we invoke it, it wouldn't create a different output.
For our count
value, we can visualize what happened with the two updates in two different scopes in the figure below.
Get hands-on with 1400+ tech skills courses.