I am trying to reset its field of a form after an async function completes execution. However, when the async function completes its instructions, I found that the e.currentTarget (where e is the React.FormEvent<HtmlFormElement> object). Here is the code please review and let me know what was wrong in my code:
onAddFormSubmitted(e: React.FormEvent<HTMLFormElement>): Promise<void> { e.preventDefault(); const formdata = new FormData(e.currentTarget); // e.currentTarget.reset(); // it worked here if (formdata) { const book: Book = { title: formdata.get("booktitle") as string, author: formdata.get("authorname") as string, } addBook(book).then((doc) => { book.id = doc.id; this.props.onBookCreated(book); e.currentTarget.reset(); // e.currentTarget becoming null at this point. Why? }); } } I am trying to reset form element after the asynchronous function call. But, the currentTarget object becomes null.