import React, { useState } from "react"
import { useAsync } from "react-async"
const subscribe = ([email], props, { signal }) =>
fetch("/newsletter", { method: "POST", body: JSON.stringify({ email }), signal })
const NewsletterForm = () => {
const { isPending, error, run } = useAsync({ deferFn: subscribe })
const [email, setEmail] = useState("")
const handleSubmit = event => {
<form onSubmit={handleSubmit}>
<input type="email" value={email} onChange={event => setEmail(event.target.value)} />
<button type="submit" disabled={isPending}>
{error && <p>{error.message}</p>}