Search code examples
javascripthtmlreactjsonchange

onchange vs onChange differences and when to use?


Just working through a problem and I'm noticing HTML has an onchange Event, and React has an onChange event handler. Was wondering what the big difference between the two would be, outside one being available with React and the other is not

The question I'm being asked is telling me to use the event object being passed to my function. I see React's onChange method passes an event object to the handleChange function so I'm assuming I am going to use that. Does the html onchange do the same?

Sorry if this is confusing.

I guess I'm basically asking when I should use one, opposed to the other? I know in my circumstance I should be using onChange.. but it has me curious when I should use onchange, if ever at all?

Thanks in advance!


Solution

  • I think this question and its answer will explain it very detailed for you Why onchange behaves differently on React vs HTML.

    And for your question

    when I should use onchange, if ever at all?

    From my experience, there is no circumstance that we should use onchange in a React app. React provides enough tools for us to handle events. Furthermore, preferring using React features in your React app makes the code more readable and testable.