Skip to content

Instantly share code, notes, and snippets.

@nirnejak
Last active May 30, 2023 10:41
Show Gist options
  • Save nirnejak/6a3f34f2512835f0261bffad98cd17b1 to your computer and use it in GitHub Desktop.
Save nirnejak/6a3f34f2512835f0261bffad98cd17b1 to your computer and use it in GitHub Desktop.
import * as React from "react"
type ContactFormInput = {
name: string
email: string
message: string
}
const initialState: ContactFormInput = {
name: "",
email: "",
message: "",
}
const ContactSection: React.FC = () => {
const [state, setState] = React.useState<ContactFormInput>(initialState)
const handleInput: React.ChangeEventHandler<
HTMLInputElement | HTMLTextAreaElement
> = (event) => {
setState({
...state,
[event.target.name]: event.target.value,
})
}
const handleSubmit: React.FormEventHandler = async (e) => {
e.preventDefault()
const response = await fetch("/api/contact", {
body: JSON.stringify(state),
headers: {
"Content-Type": "application/json",
},
method: "POST",
})
const data = await response.json()
console.log(data)
}
return <div></div>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment