I'm making a textbox that either handlesclick on enter or changes text to SVG on space click. However, react is only considering the first if statement, using else works, but else if gets completely ignored.
textbox code:
<input type="text" id="textbox" contentEditable="true" className="grinputbox"
onChange={(e) => {setInput(e.target.value)}}
onKeyPress={twoCalls}
/>
TwoCalls function:
const twoCalls = (e) => {
if (e.key === "Enter") {
console.log("enter");
handleClick()
} else if (e.key === "Space") {
console.log("space");
toSVG()
}
}
It does console log enter on pressing enter, however no space on pressing space
keypress/onkeypressare deprecated, according to MDN: developer.mozilla.org/en-US/docs/Web/API/Document/…. It would be better to switch to usingkeydown/onkeydown