Training Grounds
Handler Runs on Load - Not on ClickWhite Belt
+10 Ki
Description

A feedback form lets users click a button to submit their rating. The submission should only happen when the button is clicked.

Anomaly

The submission fires immediately when the page loads. Clicking the button after that does nothing

Constraint
Do not add any new hooks
Hint

Look at how the handler is attached to the button - is it being called or passed?

Consult the SenseiOnly for those truly stuck · Flip to reveal

Look at how the handler is attached to the button - is it being called or passed?

Loading editor…
Correct Solution
Loading...

Why this fixes it

onClick={handleSubmit()} called handleSubmit immediately during render, setting submitted to true before any click happened — so the thank you message appeared on load and the button never rendered again. Removing the parentheses to onClick={handleSubmit} passes the function reference itself so React calls it only when the button is actually clicked.

Expected OutputGoal State
Your OutputLive