0

In React, onChange in the following code is regarded as an on input event handler, not on change, if I understand correctly:

<input onChange={() => ()}></input>

But I do want to handle on change events. How do I do that?

Updates:

In React, onChange will be triggered on input events, so it cannot handle on-change events (for HTMLInputElement).

I want to handle on-change events, not on-input events.

naughie
  • 315
  • 2
  • 14
  • 1
    Check this out if that helps : https://stackoverflow.com/questions/38256332/in-react-whats-the-difference-between-onchange-and-oninput – Abhishek Sharma Mar 19 '21 at 05:03
  • I'm not quite sure this is a duplicate question, but I certainly think the above link will get you straightened out. – Drew Reese Mar 19 '21 at 05:06
  • Yeah, I know what the answers to the link say (as I mentioned), but that does not give any answer to 'how to handle (literally) on-change events.' – naughie Mar 19 '21 at 05:12
  • What do you need to do? Do you just need a working example? https://reactjs.org/docs/handling-events.html – Drew Reese Mar 19 '21 at 05:17
  • Above link says that there are no differences between `on input` and `on change` in React's point of view, while they are different in the DOM's world. I want to handle `on change` of the input element in DOM's sense (*not* in React's sense). – naughie Mar 19 '21 at 05:39
  • For `on change`, I mean this: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/change_event But `onChange` in React is triggered on input events: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/input_event – naughie Mar 19 '21 at 05:43
  • See my updated question. – naughie Mar 19 '21 at 05:48
  • Ok, so nearly all of my JS/web development experience has been in React, so this distinction makes no sense to me. It's clear though that React handles `onChange` events a specific way. What does the React `onChange` handling not do that you are wanting? – Drew Reese Mar 19 '21 at 06:22
  • Oh, I see. So there should be some alternatives. Hmm `onBlur` might do what I want. Ok, I will try it. – naughie Mar 19 '21 at 06:41

1 Answers1

0

Although they are not exactly the same, onBlur handler does what I would like.

naughie
  • 315
  • 2
  • 14