26
Uncaught (in promise) SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
Hi! I get above error from my ContactForm.js component. This error is because the response body of fetch is not in JSON format. How to convert it into JSON format?
import React, {useState} from "react";
import Minimal7 from '../img/minimal7.jpg';
import Minimal6 from '../img/minimal6.jpg';
import Minimal5 from '../img/minimal5.jpg';
import {FaFacebookSquare, FaInstagramSquare, FaPinterestSquare } from "react-icons/fa";
const ContactForm = () => {
const [status, setStatus] = useState("Submit");
const handleSubmit = async (e) => {
e.preventDefault();
setStatus("Sending...");
const { name, email, subject, business, datetime, launch, message } = e.target.elements;
let details = {
name: name.value,
email: email.value,
subject: subject.value,
business: business.value,
datetime: datetime.value,
launch: launch.value,
message: message.value,
};
let response = await fetch("https://delightart.co/send", {
method: "POST",
headers: {
"Content-Type": "application/json;charset=utf-8",
},
body: JSON.stringify(details),
}).then(res => res.json())
.then(res => console.log(res));
setStatus("Submit");
let result = await response.json();
console.log(result);
alert(result.status);
};
return (
I'd love to hear from you! I aim to answer all emails whithin my normal business hours of M-F, 9-4pm.
Use the form below or email me at [email protected]
CONTACT
export default ContactForm;
export function Design() {
return (
Have questions? Check our:
Design services
26