Skip to main content

Newsletter Components

2 Components

React components for newsletter signup forms and subscriber preference management.

Quick Start

Newsletter components are available from the SDK. Wrap your app with SylphxProvider for automatic configuration.
Installation
import { NewsletterForm, SubscriberPreferences } from '@sylphx/sdk/react'

NewsletterForm

A complete email capture form with validation, loading states, and success/error handling. Supports double opt-in and preference selection.

SSR Compatible
Auto-validation
Basic Usage
import { NewsletterForm } from '@sylphx/sdk/react'

export function Footer() {
  return (
    <footer>
      <h3>Subscribe to our newsletter</h3>
      <NewsletterForm />
    </footer>
  )
}

Props

PropertyTypeDescription
variant"inline" | "stacked"= "inline"Layout variant - inline has input and button on same line
preferencesstring[]= ["all"]Pre-selected preferences for the subscriber
showPreferencesboolean= falseShow preference checkboxes in the form
availablePreferencesPreference[]Available preferences to show as checkboxes
sourcestring= "website"Source identifier for tracking signups
metadataobjectAdditional metadata to attach to subscriber
placeholderstring= "Enter your email"Email input placeholder text
buttonTextstring= "Subscribe"Submit button text
successMessagestring= "Check your email to confirm!"Message shown after successful subscription
onSuccess(email: string) => voidCallback when subscription is successful
onError(error: Error) => voidCallback when subscription fails
classNamestringAdditional CSS classes for the form container

Variants

// Input and button on same line - great for footers
<NewsletterForm variant="inline" />

// Renders:
// +--------------------------------------------------+
// | [Enter your email...           ] [Subscribe]     |
// +--------------------------------------------------+

With Preferences

Show preference selection
<NewsletterForm
  showPreferences={true}
  availablePreferences={[
    { id: 'product_updates', label: 'Product Updates', description: 'New features & releases' },
    { id: 'promotions', label: 'Promotions', description: 'Special offers & discounts' },
    { id: 'weekly_digest', label: 'Weekly Digest', description: 'Best content summary' },
  ]}
  preferences={['product_updates']} // Pre-selected
/>

// Renders:
// +------------------------------------------+
// | [Enter your email...           ]         |
// |                                          |
// | ☑ Product Updates                        |
// |   New features & releases                |
// | ☐ Promotions                             |
// |   Special offers & discounts             |
// | ☐ Weekly Digest                          |
// |   Best content summary                   |
// |                                          |
// | [          Subscribe          ]          |
// +------------------------------------------+

Custom Styling

Themed form
<NewsletterForm
  variant="stacked"
  className="bg-gradient-to-br from-primary/10 to-primary/5 p-8 rounded-2xl"
  placeholder="your@email.com"
  buttonText="Get Updates"
  successMessage="🎉 You're in! Check your inbox."
  onSuccess={(email) => {
    analytics.track('newsletter_subscribed', { email })
  }}
/>

States

The component handles all states automatically:

Idle

Ready for input

Loading

Submitting subscription

Success

Shows confirmation message

Error

Shows error with retry

SubscriberPreferences

Allows subscribers to manage their email preferences, update frequency, or unsubscribe. Perfect for preference centers and unsubscribe pages.

SSR Compatible
Auto-fetching
Basic Usage
import { SubscriberPreferences } from '@sylphx/sdk/react'

// In your preference center page
export function PreferencesPage({ subscriberToken }: { subscriberToken: string }) {
  return (
    <div className="max-w-md mx-auto">
      <h1>Email Preferences</h1>
      <SubscriberPreferences token={subscriberToken} />
    </div>
  )
}

Props

PropertyTypeDescription
tokenstringSubscriber token from email link (required)
emailstringSubscriber email (alternative to token if authenticated)
showUnsubscribeboolean= trueShow unsubscribe from all option
showFeedbackboolean= trueShow feedback field on unsubscribe
onUpdate(preferences: string[]) => voidCallback when preferences are updated
onUnsubscribe(reason?: string) => voidCallback when user unsubscribes
classNamestringAdditional CSS classes

Unsubscribe Page

app/unsubscribe/page.tsx
import { SubscriberPreferences } from '@sylphx/sdk/react'

export default function UnsubscribePage({
  searchParams,
}: {
  searchParams: { token: string }
}) {
  return (
    <div className="min-h-screen flex items-center justify-center p-4">
      <div className="max-w-md w-full">
        <h1 className="text-2xl font-bold mb-2">Email Preferences</h1>
        <p className="text-muted-foreground mb-6">
          Choose which emails you'd like to receive, or unsubscribe from all.
        </p>

        <SubscriberPreferences
          token={searchParams.token}
          showFeedback={true}
          onUnsubscribe={(reason) => {
            // Track unsubscribe reason
            analytics.track('newsletter_unsubscribed', { reason })
          }}
        />
      </div>
    </div>
  )
}

Secure Tokens

The token in unsubscribe links is a signed JWT that identifies the subscriber. It expires after 30 days for security.

useNewsletter Hook

For custom UI, use the useNewsletter hook to access newsletter functionality:

Custom Newsletter Form
import { useNewsletter } from '@sylphx/sdk/react'

function CustomNewsletterForm() {
  const {
    subscribe,
    loading,
    error,
    success,
  } = useNewsletter()

  const [email, setEmail] = useState('')

  const handleSubmit = async (e: React.FormEvent) => {
    e.preventDefault()
    await subscribe({
      email,
      preferences: ['product_updates'],
      source: 'custom_form',
    })
  }

  return (
    <form onSubmit={handleSubmit}>
      <input
        type="email"
        value={email}
        onChange={(e) => setEmail(e.target.value)}
        placeholder="Enter your email"
        disabled={loading}
      />
      <button type="submit" disabled={loading}>
        {loading ? 'Subscribing...' : 'Subscribe'}
      </button>

      {success && <p className="text-success">Check your email!</p>}
      {error && <p className="text-destructive">{error.message}</p>}
    </form>
  )
}

Hook Return Value

PropertyTypeDescription
subscribe(options) => Promise<void>Subscribe an email to the newsletter
updatePreferences(email, prefs) => Promise<void>Update subscriber preferences
unsubscribe(email, reason?) => Promise<void>Unsubscribe from newsletter
loadingbooleanLoading state for async operations
errorError | nullError from last operation
successbooleanSuccess state for last operation
reset() => voidReset success/error state

Best Practices

Prominent Placement

Place NewsletterForm in high-visibility areas: footer, sidebar, after valuable content.

Value Proposition

Tell users what they'll get. "Get weekly tips" is better than just "Subscribe".

Easy Unsubscribe

Make it easy to unsubscribe. It builds trust and is legally required.

Confirmation Feedback

Always show clear feedback after subscription. Guide users to check their email.

Ready to build your newsletter?

Learn more about subscriber management, campaigns, and analytics.