Datasets:
Download tasks/c20/repo/src/components/NewsletterForm.jsx from Roy-DOU/Webdev-Bench: direct link, hf CLI and curl.
- Browser
- Download file 1.87 kB
-
https://huggingface.co/datasets/Roy-DOU/Webdev-Bench/resolve/main/tasks/c20/repo/src/components/NewsletterForm.jsx
- Command line
-
hf download hf://datasets/Roy-DOU/Webdev-Bench/tasks/c20/repo/src/components/NewsletterForm.jsx
-
curl -L -o NewsletterForm.jsx https://huggingface.co/datasets/Roy-DOU/Webdev-Bench/resolve/main/tasks/c20/repo/src/components/NewsletterForm.jsx
1.87 kB
| import { useRef, useState } from 'react' | |
| import recaptcha from '../assets/recaptcha.png' | |
| export default function NewsletterForm({ variant }) { | |
| const [email, setEmail] = useState('') | |
| const [name, setName] = useState('') | |
| const [accepted, setAccepted] = useState(false) | |
| const [sent, setSent] = useState(false) | |
| const [confirmedEmail, setConfirmedEmail] = useState('') | |
| const submitCount = useRef(0) | |
| function handleSubmit(e) { | |
| e.preventDefault() | |
| const requestedEmail = email | |
| submitCount.current += 1 | |
| const delay = Math.max(400, 1200 - (submitCount.current - 1) * 800) | |
| setTimeout(() => { | |
| setSent(true) | |
| setConfirmedEmail(requestedEmail) | |
| }, delay) | |
| } | |
| return ( | |
| <form className={`newsletter-form ${variant}`} onSubmit={handleSubmit}> | |
| <label className="accept-row"> | |
| <input | |
| type="checkbox" | |
| checked={accepted} | |
| onChange={(e) => setAccepted(e.target.checked)} | |
| /> | |
| </label> | |
| <p className="accept-text"> | |
| I accept the <a href="#">terms and conditions</a> | |
| </p> | |
| <input | |
| className="text-input" | |
| type="email" | |
| placeholder="Email address*" | |
| required | |
| value={email} | |
| onChange={(e) => setEmail(e.target.value)} | |
| /> | |
| <input | |
| className="text-input" | |
| type="text" | |
| placeholder="Name" | |
| value={name} | |
| onChange={(e) => setName(e.target.value)} | |
| /> | |
| <button className="subscribe-btn" type="submit"> | |
| SUBSCRIBE | |
| </button> | |
| {sent && ( | |
| <p className="form-feedback"> | |
| Bedankt voor je aanmelding! We hebben je ingeschreven op{' '} | |
| <strong>{confirmedEmail}</strong>. | |
| </p> | |
| )} | |
| <img | |
| className="recaptcha" | |
| src={recaptcha} | |
| alt="reCAPTCHA: I'm not a robot" | |
| /> | |
| </form> | |
| ) | |
| } | |