On this page
  1. Install
  2. Compose a subscribe form
  3. Provider configuration
  4. Hooks and headless components
  5. API entry points and requirements
  6. Peer dependencies

@playstack/audiences-react

Headless React subscription and preference-center state with explicit clients, cache boundaries, and safe errors.

Pro. Covered by the Playstack Pro License. Registry access is required; check preview availability before installing. See package access.

@playstack/audiences-react supplies headless state for subscribe forms and token-scoped preference centers. The package root is an explicit Client Component entry point that can sit beneath a Next.js App Router Server Component boundary.

Install

sh
npm install @playstack/audiences-react @playstack/audiences react

Compose a subscribe form

tsx
'use client'

import {
  createAudiencesCache,
  PlaystackAudiencesProvider,
  useAudienceSubscribe,
} from '@playstack/audiences-react'

const cache = createAudiencesCache()

function Subscribe() {
  const subscription = useAudienceSubscribe({ listKey: 'launch' })

  return (
    <form
      onSubmit={(event) => {
        event.preventDefault()
        void subscription.submit(
          new FormData(event.currentTarget).get('email') as string,
        )
      }}
    >
      <input name="email" type="email" />
      <button disabled={subscription.status === 'loading'}>Subscribe</button>
    </form>
  )
}

export function AudienceBoundary() {
  return (
    <PlaystackAudiencesProvider client={applicationClient} cache={cache}>
      <Subscribe />
    </PlaystackAudiencesProvider>
  )
}

Provider configuration

PropertyRequiredPurpose
clientYesApplication-owned subscribe and preference API client.
cacheYesExplicit synchronous get/set/subscribe boundary.
toSafeErrorNoMaps application errors to approved UI copy.
onErrorNoSends the original error to caller-owned observability.

client.client preserves access to the underlying HTTP or query client. The package does not install a fetch global, authentication, CAPTCHA, routing, or visual styling.

Hooks and headless components

APIPurpose
useAudienceSubscribe({ listKey, cacheKey? })Submits an address, shares in-flight operations, and reports accepted or confirmation-required state.
useAudiencePreferences({ token, cacheKey })Loads and optimistically updates token-scoped preferences.
AudienceSubscribeRender-prop equivalent of the subscribe hook.
AudiencePreferenceCenterRender-prop equivalent of the preferences hook.

The preference cacheKey must be a stable, non-secret identifier. The signed token is intentionally never used as a cache key. Public subscribe responses containing subscriber IDs or signed tokens are rejected as invalid.

API entry points and requirements

Reference snapshot: @playstack/audiences-react@0.1.0-beta.1. Import only the entry point your runtime needs. Paths below are relative to the installed package; use Go to Definition in your editor to inspect exact parameters, return types and overloads. Do not import the declaration-file paths directly.

Public entry pointDeclaration file
@playstack/audiences-react./dist/index.d.ts
@playstack/audiences-react/errors./dist/errors.d.ts
@playstack/audiences-react/package.jsonNo TypeScript declaration (asset or metadata export).

Node.js engine requirement: >=20. This is not a claim that every entry point works in browsers or Workers.

Peer dependencies

Keep existing framework versions that satisfy these ranges. Install optional peers only when using the corresponding adapter. The package manager resolves ordinary dependencies separately.

PeerCompatible rangeWhen needed
@playstack/audiences0.1.0-beta.1Required by the package.
react^18.2.0 || ^19.0.0Required by the package.

For a complete first program, start with Getting started. For API lookup and partial-example conventions, see Reading the reference. Provider failures, lifecycle requirements and application responsibilities remain described in the guide above; types alone do not establish production safety.

Go

Playstack Pro tag
OriginsPricingBlogNewsletterChangelogStatusRoadmap
ContributorsCommunityIn Use ShowcaseCase StudiesPartnersSponsors
FAQsSupportContact

© 2026 Playstack. All rights reserved.

With OSS
Terms of ServicePrivacy PolicyCookie PolicyImprint

By

Commune Software