Hi Jared, thank you for this tutorial, it is very usefull for beginners like me.
I tried it, the server.js functions as you instructed. however, my App.js gives error at the first testing step.
Could you please, share the final view of App.js code please?
Many thanks,
Is it an error when trying to run/start your client side? Or is it an error when trying to send an email?
Yeah for sure. Here is the entire App.js file:
import { useState } from "react"; function App(props) { const [mailerState, setMailerState] = useState({ name: "", email: "", message: "", }); function handleStateChange(e) { setMailerState((prevState) => ({ ...prevState, [e.target.name]: e.target.value, })); } const submitEmail = async (e) => { e.preventDefault(); console.log({ mailerState }); await fetch("http://localhost:3001/send", { method: "POST", headers: { "Content-type": "application/json", }, body: JSON.stringify({ mailerState }), }) .then((res) => res.json()) .then(async (res) => { const resData = await res; console.log(resData); if (resData.status === "success") { alert("Message Sent"); } else if (resData.status === "fail") { alert("Message failed to send"); } }) .then(() => { setMailerState({ email: "", name: "", message: "", }); }); }; return ( <div className="App"> <form style={{ display: "flex", height: "100vh", justifyContent: "center", alignItems: "center", }} onSubmit={submitEmail} > <fieldset style={{ display: "flex", flexDirection: "column", justifyContent: "center", width: "50%", }} > <legend>React NodeMailer Contact Form</legend> <input placeholder="Name" onChange={handleStateChange} name="name" value={mailerState.name} /> <input placeholder="Email" onChange={handleStateChange} name="email" value={mailerState.email} /> <textarea style={{ minHeight: "200px" }} placeholder="Message" onChange={handleStateChange} name="message" value={mailerState.message} /> <button>Send Message</button> </fieldset> </form> </div> ); } export default App;
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hi Jared, thank you for this tutorial, it is very usefull for beginners like me.
I tried it, the server.js functions as you instructed. however, my App.js gives error at the first testing step.
Could you please, share the final view of App.js code please?
Many thanks,
Is it an error when trying to run/start your client side? Or is it an error when trying to send an email?
Yeah for sure. Here is the entire App.js file: