Referrals Components

1 Component

React component for building referral interfaces. Display referral links, track stats, and enable social sharing.

Quick Start

The ReferralCard component is available from the SDK. Wrap your app with SylphxProvider for automatic user context and referral data fetching.
Installation
import { ReferralCard } from '@sylphx/platform-sdk/react'

ReferralCard

A complete referral interface that displays the user's unique referral link, referral statistics (referred count, earnings), and share buttons for social platforms. Supports multiple variants for different use cases.

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

export function ReferralSection() {
  return (
    <div className="max-w-md">
      <ReferralCard />
    </div>
  )
}

Props

PropertyTypeDescription
variant"full" | "compact"= "full"Display variant - full shows all stats, compact is minimal
showStatsboolean= trueShow referral statistics (count, earnings)
showShareButtonsboolean= trueShow social share buttons
showLeaderboardboolean= falseShow referral leaderboard below the card
leaderboardLimitnumber= 5Number of users to show in leaderboard
shareMessagestring= "Join me on {appName}!"Custom message for social shares
shareChannelsShareChannel[]= ["copy", "twitter", "email"]Which share buttons to show
classNamestringAdditional CSS classes for the card container
onShare(channel: string) => voidCallback when user clicks a share button
onCopy() => voidCallback when referral link is copied
titlestring= "Invite Friends"Custom card title
descriptionstring= "Share your link and earn rewards"Custom card description

Variants

ReferralCard supports two variants optimized for different layouts:

// Full variant - ideal for dedicated referral pages
<ReferralCard variant="full" />

// Renders:
// +------------------------------------------+
// |  Invite Friends                          |
// |  Share your link and earn rewards        |
// |                                          |
// |  +------------------------------------+  |
// |  | https://app.com/ref/ABC123    [Copy]  |
// |  +------------------------------------+  |
// |                                          |
// |  [Twitter]  [Email]  [WhatsApp]  [SMS]  |
// |                                          |
// |  +----------+  +----------+  +--------+ |
// |  |    12    |  |   $120   |  |   8    | |
// |  | Referred |  |  Earned  |  | Pending| |
// |  +----------+  +----------+  +--------+ |
// +------------------------------------------+

With Leaderboard

Enable the leaderboard to gamify your referral program and drive competition:

With Leaderboard
import { ReferralCard } from '@sylphx/platform-sdk/react'

export function ReferralPage() {
  return (
    <ReferralCard
      showLeaderboard={true}
      leaderboardLimit={10}
    />
  )
}

// Renders the card plus:
// +------------------------------------------+
// |  Top Referrers This Month                |
// |                                          |
// |  1. Alice Chen         25 referrals  [Crown Icon] |
// |  2. Bob Smith          18 referrals  [Medal Icon] |
// |  3. Carol Davis        15 referrals  [Medal Icon] |
// |  4. David Lee          12 referrals              |
// |  5. Eve Wilson          8 referrals              |
// |  ...                                             |
// |  You: #7 with 5 referrals                        |
// +------------------------------------------+

Share Channels

Customize which share buttons appear:

copy

Copy link to clipboard

twitter

Share on Twitter/X

email

Share via email

whatsapp

Share on WhatsApp

sms

Share via SMS

native

Native share dialog

Custom Share Channels
<ReferralCard
  shareChannels={['copy', 'twitter', 'whatsapp', 'email']}
  shareMessage="Join me on Acme! Use my link for 20% off your first month."
  onShare={(channel) => {
    analytics.track('referral_shared', { channel })
  }}
/>

Advanced Examples

<ReferralCard
  className="bg-gradient-to-br from-purple-500/10 to-pink-500/10 border-purple-500/20"
  title="Earn $10 for Every Friend"
  description="They get 20% off, you get $10 credit"
  variant="full"
  showLeaderboard={true}
/>

Auto-fetching

ReferralCard automatically fetches the user's referral code, stats, and leaderboard data. It handles loading and error states internally.

Stats Display

The ReferralCard displays three key metrics when showStats is enabled:

Referred Count

Total number of users who signed up using this referral link

Earnings

Total rewards earned from successful referrals (credits, discounts, etc.)

Pending

Referrals awaiting conversion or verification period completion

Stats-only Display
// Show only stats without share buttons
<ReferralCard
  showStats={true}
  showShareButtons={false}
/>

Leaderboard

The integrated leaderboard gamifies your referral program by showing top referrers:

Gamification
Competition
Leaderboard Configuration
<ReferralCard
  showLeaderboard={true}
  leaderboardLimit={10}
  leaderboardPeriod="month" // 'week' | 'month' | 'all-time'
/>

// Leaderboard features:
// - Top 3 users get special badges (Crown, Gold Medal, Silver Medal)
// - Current user's position is highlighted
// - Shows referral count and earnings for each user
// - Respects privacy - shows display name, not full details

Leaderboard Badges

1st Place

Gold crown icon with highlighted row

2nd Place

Silver medal icon

3rd Place

Bronze medal icon

Related Hooks

For more control, use the useReferral hook to build custom UI:

useReferral Hook
import { useReferral } from '@sylphx/platform-sdk/react'

function CustomReferralUI() {
  const {
    referralCode,
    referralUrl,
    stats,
    leaderboard,
    loading,
    error,
    copyUrl,
    copied,
    share,
  } = useReferral()

  if (loading) return <Skeleton />
  if (error) return <ErrorMessage error={error} />

  return (
    <div>
      {/* Custom referral UI */}
      <input value={referralUrl} readOnly />
      <button onClick={copyUrl}>
        {copied ? 'Copied!' : 'Copy Link'}
      </button>

      <div className="stats">
        <span>{stats.signups} signups</span>
        <span>${stats.earned} earned</span>
      </div>

      <div className="share-buttons">
        <button onClick={() => share('twitter')}>
          Tweet
        </button>
        <button onClick={() => share('email')}>
          Email
        </button>
      </div>
    </div>
  )
}

Best Practices

Use Full Variant for Dedicated Pages

The full variant with leaderboard works best on dedicated referral pages where users are focused on sharing.

Compact for Secondary Placements

Use compact variant in sidebars, footers, or as a widget to maintain visibility without taking too much space.

Track Share Actions

Always use onShare and onCopy callbacks to track which channels drive the most referrals.

Customize Share Messages

A compelling shareMessage can significantly improve conversion rates. Include the benefit for both parties.

Ready to grow with referrals?

Learn more about configuring rewards, fraud prevention, and tracking referral performance.