Refport
SDKs

React

@refport/react provides React components and hooks for click ID tracking and rendering the embedded referral portal.

@refport/react wraps refport-js in idiomatic React APIs and provides the <RefportEmbed> component for embedding the referral portal.

Installation

npm install @refport/react
# or
pnpm add @refport/react

@refport/react requires React 18 or 19 as a peer dependency.


Click ID tracking

useRefportTracking(options?)

A hook that runs init() from refport-js on mount and returns the tracking result. Re-renders the component whenever the result changes.

'use client';

import { useRefportTracking } from '@refport/react';

export function MyComponent() {
  const { clickId, tracked, source } = useRefportTracking();

  return <p>Click ID: {clickId ?? 'none'}</p>;
}

Pass any RefportTrackingOptions as the argument.

<RefportTracker>

A renderless component that runs tracking on mount. Place it once in your root layout so you don't need to import the hook in every page.

import { RefportTracker } from '@refport/react';

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html>
      <body>
        <RefportTracker />
        {children}
      </body>
    </html>
  );
}

Props:

PropTypeDescription
optionsRefportTrackingOptionsOptions forwarded to init()
onTrack(result: RefportTrackingResult) => voidCalled whenever a click ID is present

getClickId(cookieName?)

Re-exported from refport-js. Returns the current click ID synchronously from the cookie — useful in event handlers where you don't want to subscribe to state.

import { getClickId } from '@refport/react';

function handleSubmit() {
  const clickId = getClickId();
  // send clickId to your server
}

reset(options?)

Re-exported from refport-js. Clears the tracking cookie.


Embedded referral portal

<RefportEmbed>

Renders an iframe containing the partner referral portal. The portal adjusts its height dynamically to fit its content.

import { RefportEmbed } from '@refport/react';

export default function ReferralPage({ token }: { token: string }) {
  return (
    <RefportEmbed
      token={token}
      theme="system"
    />
  );
}

The token must be a short-lived public token generated server-side with embedTokens.create(). See Embedded Portal for the full server + client setup.

Props:

PropTypeDefaultDescription
tokenstringRequired. Public embed token from embedTokens.create()
theme"light" | "dark" | "system"Color scheme for the portal iframe
themeOptionsobjectOverride individual theme colors
themeOptions.backgroundColorstringBackground color (CSS value)
themeOptions.primaryColorstringAccent/primary color
themeOptions.textColorstringMain text color
cssVarsRecord<string, string>Inject arbitrary CSS variables into the portal
baseUrlstringhttps://app.refport.coOverride the Refport app URL
onError(error: { code: string; message: string }) => voidCalled if the portal reports an error
styleCSSPropertiesStyles applied to the wrapping <div>

Any additional div props (e.g. className, id) are forwarded to the container element.


TypeScript types

import type { RefportTrackingOptions, RefportTrackingResult, RefportEmbedProps } from '@refport/react';

On this page