With a create-react-app boilerplate setup, I have an input field with an onFocus event passed. Within this onFocus callback I'm setting a click eventlistener on window.document.
When the input field is focused why does the clickHandler callback fire immediately?
function App() {
const clickHandler = (e) => {
console.log("clicked");
window.document.removeEventListener("click", clickHandler)
}
const focusHandler = (e) => {
console.log('onFocus');
e.stopPropagation()
window.document.addEventListener("click", clickHandler)
}
return (
<div className="App">
<input onFocus={focusHandler} />
</div>
);