In plain words
State is the data a screen keeps in memory, like the items in a cart or whether a menu is showing, and changing it makes the screen redraw.
Where you see it
You tap + on a QuickBite dish and the quantity goes from 1 to 2 while the total updates. Nothing was saved anywhere: that number lives in state, which is why it's back to 1 after a refresh.
What goes wrong
- Changing a list in place
React redraws when state gets a new value. Pushing into the existing array changes the data, but React doesn't notice and the cart badge stays at 2.
cart.push(dish); setCart(cart); - Expecting state to survive a refresh
State lives in the open tab's memory. Anything that must outlast a refresh, or show up on another device, belongs in the database.
- The same data kept in two places
Keep the cart in one component's state and a copy in another, and they drift apart: the badge says 3, checkout says 2. Keep one source and pass it down.
What to tell your agent
Quick check
Sign in to earn +10 XP for itMaya adds a note in Quill, refreshes the page, and the note is gone. What happened to it?