// src/components/NewsletterSignup.jsx import { useState } from 'react'; export default function NewsletterSignup() { const [email, setEmail] = useState(''); const [sent, setSent] = useState(false); async function handleSubmit(e) { e.preventDefault(); await fetch('/api/subscribe', { method: 'POST', body: JSON.stringify({ email }), }); setSent(true); } return sent ? (

Thanks — you're subscribed!

) : (
setEmail(e.target.value)} />
); } // src/pages/api/subscribe.ts export async function POST({ request }) { const { email } = await request.json(); console.log('New subscriber:', email); return new Response(JSON.stringify({ status: 'ok' }), { headers: { 'Content-Type': 'application/json' }, }); } --- // src/pages/blog/index.astro (updated) import BaseLayout from '../../layouts/BaseLayout.astro'; import NewsletterSignup from '../../components/NewsletterSignup.jsx'; import { getCollection } from 'astro:content'; const posts = await getCollection('blog'); ---