javascriptreactjsdomreact-hooks

Detecting which input is focused React hooks


I'm using React Hooks. I want to check which input is focused. I have an object of dynamically generated inputs. The inputs will be selected and I want to have a button that will append a value to the input that is in focus.


Solution

  • Try to add events on Focus and on Focus Lost.

    W3Schools Reference

     <input type="text" onFocus="this.props.onFocus()" onFocusOut="this.props.lostFocus()">