A component shows either a secret message or a hide button. Clicking the button should toggle visibility. It never toggles — the message stays hidden forever.
The button says "Show Secret" and clicking it does nothing. The secret message never appears.
What is the onClick handler actually setting visible to?
What is the onClick handler actually setting visible to?
Why this fixes it
The click handler called setVisible(false) unconditionally, meaning every click set visible to false regardless of its current value - so the message could never appear. Replacing that with setVisible((v) => !v) passes a functional updater that receives the current state value and inverts it. Because the updater always receives the latest committed state, visible flips correctly between true and false on each click.