const handleSubmit = async ( e: React.FormEvent<HTMLFormElement> ): Promise<void> => {…
- User
const handleSubmit = async ( e: React.FormEvent ): Promise => { e.preventDefault(); // 👇 encode the data to application/x-www-form-urlencoded type const formData = new URLSearchParams(); formData.append("email", email); // 👇 call backend endpoint using fetch API fetch("/api/subscribe", { body: formData.toString(), method: "post", headers: { "content-type": "application/x-www-form-urlencoded", }, }).then(async (result) => { // 👇 modify the state to show the result setResult(await result.json()); }); }; rewrite to javascript
- Assistant
const handleSubmit = async (e) => { e.preventDefault(); const formData = new URLSearchParams(); formData.append("email", email); fetch("/api/subscribe", { body: formData.toString(), method: "post", headers: { "content-type": "application/x-www-form-urlencoded", }, }).then(async (result) => { setResult(await result.json()); }); };