React State & Reactivity
Normal variables don't tell React to update the screen. If you want a component to "remember" information and update when that info changes, you need State.
The useState Hook
useState gives you an array with two elements. The first is the current state value. The second is a function that lets you update it. We use array destructuring to assign them names.
Triggering Renders
When you call the state setter function (e.g., setCount(1)), React queues a re-render. It calls your component function again, this time providing the new state value.
Immutability
State should be treated as read-only. Never modify an object or array in state directly. Instead, create a new object or array, and pass that to the setter function. This is how React knows for sure that a change has occurred.
View Full Transcript+
This section contains the full detailed transcript of the video lessons. It covers the difference between local variables and state, how the virtual DOM diffs changes, and why immutability is crucial for performance optimization in React applications.
