πŸ§‘β€πŸ’» Software Engineering🧩 Snippets❇️ Getting Know the Submit Event

❇️ Getting Know the Submit Event

The use case:

  • I want to know the submitter button because I have multiple buttons in the form. In react-hook-form the handleSubmit function will return the submit event.
const onSubmit = (
  data,
  e: FormEvent<HTMLFormElement>
) => {
  const submitter = e?.nativeEvent?.submitter as HTMLButtonElement;
  const actionName = submitter?.name || 'propose';
 
  console.log('Submit action :::', actionName);
};
πŸ“ The Bookmarks by MZP, since 2024