Events in React — React Technical Interview Questions & Answers

Events in React

Events in React

  • React events are camelCase: onClick, onChange, onSubmit. You pass a function: onClick={handleClick}. If you write onClick={handleClick()} it runs during render — classic bug. Synthetic events wrap the browser event so the API is the same across browsers.
  • Need the event in a delayed callback? Save e.target.value first, or call e.persist() in very old React. In modern React 17+ pooling is gone, but still copy values you need later. For lists, pass an id: onClick={() => remove(id)}.
  • Events in React — click Save → console: saved. onClick={handleClick} not onClick={handleClick()}.

Technical Interview Tip: onClick={fn} not fn(). camelCase.

Code Examples for Events in React

Example

// Events
export default function Save() {
  function handleClick() {
    console.log("saved");
  }
  return <button onClick={handleClick}>Save</button>;
}

Events in React — click Save → console: saved. onClick={handleClick} not onClick={handleClick()}.

How to Explain Events in React to an Interviewer

Explain Events as if you are teaching a junior — definition, then one tiny UI.

camelCase, pass the function. onClick={fn()} on render.

Write 5–10 lines that use Events and say what the UI does.

Show JSX Say the screen

What mistake do freshers make with Events?

List : () => remove(id).