Buttons in React — React Technical Interview Questions & Answers
Buttons in React
Buttons in React
- A button is still HTML. In React: type="button" inside forms so it doesn’t submit, onClick={handler}, disabled={busy}, label from state (Save / Saving…). Extract <Button> when the same styles repeat. That’s it — don’t over-abstract a native control on day one.
- Buttons in React — on screen: Save. busy true → Saving… and disabled. type=button so it doesn’t submit a parent form.
Technical Interview Tip: type, onClick, disabled.
Code Examples for Buttons in React
Example
// Button
export default function Save({ busy }) {
return (
<button type="button" disabled={busy} onClick={() => console.log("save")}>
{busy ? "Saving…" : "Save"}
</button>
);
}
Buttons in React — on screen: Save. busy true → Saving… and disabled. type=button so it doesn’t submit a parent form.
How to Explain Buttons in React to an Interviewer
Explain Buttons as if you are teaching a junior — definition, then one tiny UI.
type=button in forms. onClick + disabled from state.
What does the example show on screen (or print), and what does that prove?
Buttons in React — on screen: Save
What mistake do freshers make with Buttons?
default submit type.