State
State
Values the screen is remembering right now, like the cart count, an open menu, or text being typed. When they change, the screen changes too.
💡 It's the numbers on a scoreboard. When the number (state) changes, the scoreboard (screen) redraws itself.
🤖 Say this to your AI
Manage the like button with state so the number goes up by 1 right away. It should stay after a refresh, so save it on the server too, and if saving fails, put the number back.
The key word is ‘State’. Including it helps AI understand you much more precisely.
📌 Good to know
State disappears when you refresh. Values that need to stay should be saved in localStorage or a database.
When to use it
- When you click a button but the screen doesn't change
- When values disappear after a refresh
- When the AI talks about 'state management'
Also called: state, usestate, state management, zustand, redux, global state, screen not updating, value resets