Reputation: 366
I am trying to create an emailing api for which i have a form. But it showing an error saying
Uncaught TypeError: e.preventDefaults is not a function
What is the problem here and is the syntax with axios function right?
const [name,setName] = useState("");
const [email,setEmail] = useState("");
const [message,setMessage] = useState("");
const [sent,setSent] = useState(false);
const formSubmit=(e)=> {
e.preventDefaults();
let data = {
name:name,
email:email,
message:message
}
axios.post('/api/forma',data)
.then(res => {
setSent(true);
},resetForm())
.catch(() => {
console.log("message not sent");
})
}
const resetForm = () => {
setName("");
setEmail("");
setMessage("");
setTimeout(()=> {
setSent(false);
},3000)
}
Upvotes: -1
Views: 49
Reputation: 2849
Fix e.preventDefaults();
to e.preventDefault();
. You made a typo mistake.
Upvotes: 4