A profile panel reads from a selected user object and displays a personalised greeting. Clicking a different user button should update the greeting immediately.
Click any user button - the greeting never changes from the first user's name. The button label updates correctly but the panel stays stale.
The effect runs once and captures something - what did it capture and when?
The effect runs once and captures something - what did it capture and when?
Why this fixes it
The effect closed over `user` at mount with an empty dependency array, permanently capturing the first user object. Every subsequent user selection updated state but the effect never re-ran, so the greeting stayed frozen on Alice. Adding `user` to the dependency array tells React to re-run the effect whenever `user` changes - each button click updates `user`, the effect fires again, and the greeting reflects the currently selected user.