Training Grounds
Announcement Stays on ScreenWhite Belt
+10 Ki
Description

An announcement board shows a message with a button that is supposed to replace it with a confirmation when clicked. Clicking Dismiss has no visible effect.

Anomaly

The button responds to clicks but the original message never leaves the screen regardless of how many times it is pressed.

Constraint
Do not add useEffect or any other hook
Hint

Think about what React checks to decide whether the screen needs to update after an action.

Consult the SenseiOnly for those truly stuck · Flip to reveal

Think about what React checks to decide whether the screen needs to update after an action.

Practice 34 related drills →
Loading editor…
Correct Solution
Loading...

Why this fixes it

The component read `announcement` from a plain variable declared outside any React hook. When `handleDismiss` assigned a new string to it, the assignment succeeded at the JavaScript level but React had no way to detect the change - it only schedules re-renders in response to state or prop updates through its own APIs. Moving `announcement` into `useState` connects the value to React's update cycle so every call to `setAnnouncement` triggers a re-render and the component re-executes with the new value shown on screen.

Expected OutputGoal State
Your OutputLive