Answers for "how to make when user hit enter key submit form without button in react js"

2

react form submission when enter is pressed

useEffect(() => {
    const listener = event => {
      if (event.code === "Enter" || event.code === "NumpadEnter") {
        console.log("Enter key was pressed. Run your function.");
        event.preventDefault();
        // callMyFunction();
      }
    };
    document.addEventListener("keydown", listener);
    return () => {
      document.removeEventListener("keydown", listener);
    };
  }, []);
Posted by: Guest on June-09-2021

Code answers related to "how to make when user hit enter key submit form without button in react js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language