0

I am trying to do some research to look for solution. I seem not to find any. Why are onChange and onKeyDown event trigger at the same time ?

Output:

onKeyDown

onChange


import React, {useState} from 'react';

function App() {
  
  const onHandleChange = () => {
    console.log("onChange");
  }
  const onHandleKeyDown = () => {
    console.log("onKeyDown");
  }

  return (
    <div className="App">

      <input 
        onChange={onHandleChange}
        onKeyDown= {onHandleKeyDown}
      
      />

    </div>
  );
}

export default App;

  • What do you mean by "same time". Events always run in a specific order, you can see the order: https://stackoverflow.com/questions/282245/dom-event-precedence – zecuria Sep 02 '21 at 22:44
  • *"I am trying to do some research to look for solution. I seem not to find any."* What problem are you trying to solve that this specific order of events matters? – 3limin4t0r Sep 02 '21 at 22:47

1 Answers1

0

Because they are associated with the same input. when input is changed both functions are executed. I suggest you describe what you are trying to achieve in this frame of work, so probably others can tell you how to