import { useState } from "react"; import emailjs from "@emailjs/browser"; const initialState = { name: "", email: "", message: "", }; export const Contact = (props) => { const [{ name, email, message }, setState] = useState(initialState); const handleChange = (e) => { const { name, value } = e.target; setState((prevState) => ({ ...prevState, [name]: value })); }; const clearState = () => setState({ ...initialState }); const handleSubmit = (e) => { e.preventDefault(); console.log(name, email, message); {/* replace below with your own Service ID, Template ID and Public Key from your EmailJS account */ } emailjs .sendForm("YOUR_SERVICE_ID", "YOUR_TEMPLATE_ID", e.target, "YOUR_PUBLIC_KEY") .then( (result) => { console.log(result.text); clearState(); }, (error) => { console.log(error.text); } ); }; return (
); };