I am trying to send the state object of my component. I was using a class component and converted it to a function utilising useState()
but now I can't access the state object using this.state
.
I have substituted it by creating an object called state
but I am guessing this isnt the most elegant solution...
export default function Contact () {
const [name, setName] = useState("")
const [email, setEmail] = useState("")
const [enquiryType, setEnquiryType] = useState("General Enquiry")
const [message, setMessage] = useState("")
const state = {
name,
email,
enquiryType,
message
}
const handleSubmit = (e) => {
e.preventDefault()
console.log(state) // vs this.state
var service_id = "default_service";
var template_id = "message_template";
var user_id = "user_[whatever]"
emailjs.send(service_id, template_id, state, user_id); // vs this.state
}
}