SDKsReact Native

Migrate to 1.0

Move a 0.x React Native integration to the 1.0 API: module-scope Koah.init, adContext everywhere, and per-axis KoahAxisSize sizing.

Prompt for coding agents

I use Koah's React Native SDK (koah-react-native) at a 0.x version. Migrate my integration to the 1.0 API. Read https://docs.koahlabs.com/sdk/react-native/migration and apply it to this project.

What changes

Aspect0.x1.0
Initialization<KoahProvider publisherId="..." debug={...} options={{ baseUrl }}>Koah.init({ publisherId, logLevel?, baseUrl? }) at module scope, then <KoahProvider client={koah}>
Loggingdebug: booleanlogLevel: KoahLogLevel (NONE / ERROR / WARNING / INFO / DEBUG)
Ad contentadContext optional, or legacy props (question / response / messageId / conversationId / isResponseReady, feed text / source / description)adContext required on KoahTextAdComponent / KoahFeedAdComponent. Legacy props removed.
SizingoverrideMaxWidth / overrideMaxHeight (dp), widthBehavior: "fill" | "wrap", deprecated sizewidth / height: KoahAxisSize (fixed(dp) / range({ min, max }) / fill()); omit an axis to hug content
Cached slot<KoahCachedAdComponent messageId={...}><KoahCachedAdComponent cacheKey={...}> (rename only)
Imperative fetchKoah.process, generateTextAd, prefetch, resolveAd, cancelPrefetchkoah.requestAd({ adContext, cacheKey }), prefetchAd(...), cancelPrefetchAd(cacheKey)
HooksuseKoahAd, useKoahRequestAdRemoved. Render via the components; fetch via koah.requestAd / prefetchAd.
Result{ filled, format?, fromCache }Discriminated union on kind: "filled" / "noFill" / "error" (no format)
Lifecycle callbacksdidReceiveAd, shouldGenerateAdonEvent: (event: KoahEvent) => void on every component (onFill / onNoFill remain on the feed component)
ErrorsExported KoahError classRemoved — the SDK throws native Error types
Poll trackingkoah.trackPollVoted(queryExternalId)Removed — poll votes are recorded automatically
Preview formatsKoahAdSize + KoahPreviewFormat.cardText, ...KoahAdSize removed; KoahPreviewFormat.cardTextMd, ...

Initialization

Initialize once at app entry (module scope) and pass the instance to the provider. KoahProvider no longer takes publisherId, debug, or options.

import { KoahProvider, KoahBrowserModal } from 'koah-react-native'

export default function App() {
  return (
    <KoahProvider publisherId="YOUR_PUBLISHER_ID" debug={__DEV__}>
      <YourApp />
      <KoahBrowserModal />
    </KoahProvider>
  )
}

Why init moved out of render: an uncaught throw during a React render is reported by React Native as a fatal native crash of the host app, so a bad publisher ID crashed the app mid-render. With module-scope Koah.init, a configuration error surfaces at your own call site during integration instead.

Ad components: legacy props to adContext

adContext is now required. The legacy request props are removed.

<KoahTextAdComponent
  question={userMessage}
  response={aiResponse}
  messageId={message.id}
  conversationId={conversation.id}
  isResponseReady={!isStreaming}
/>

Feed components move the same way:

<KoahFeedAdComponent
  text={post.text}
  source={post.source}
  description={post.description}
/>

Sizing: overrideMax* / widthBehavior to KoahAxisSize

<KoahTextAdComponent
  adContext={KoahAdContext.conversation({ question, answer })}
  cacheKey={messageId}
  overrideMaxWidth={384}
  overrideMaxHeight={400}
  widthBehavior="wrap"
/>

Mapping:

  • overrideMaxWidth={n} → width={KoahAxisSize.range({ max: n })} (same for height).
  • widthBehavior="fill" → width={KoahAxisSize.fill()}.
  • widthBehavior="wrap" → omit width (hugging content is the new default).
  • The deprecated size prop is removed with no direct replacement — omit both axes, or pass range bounds matching your slot.

Cached slots: messageId to cacheKey

A rename only — the value and behavior are unchanged. It is the same key you passed to prefetchAd({ cacheKey }).

<KoahCachedAdComponent messageId={post.id} />

Imperative calls and hooks

The query-based methods and the hooks are removed. Use the adContext-based methods on the instance Koah.init returned.

koah.prefetch(query, queryResponse, messageId, conversationId)
const ad = await koah.resolveAd(query, queryResponse, messageId, conversationId)
koah.cancelPrefetch(messageId)

Koah.process(...) and Koah.generateTextAd(...) are removed the same way — build a KoahAdContext and call requestAd. The useKoahAd and useKoahRequestAd hooks are removed: render through the components (which fetch for you), or pair prefetchAd with KoahCachedAdComponent. koah.trackPollVoted(...) is also removed — poll votes are recorded automatically when the visitor taps an option.

Results: filled flag to a kind union

KoahAdResult is now a discriminated union — KoahAdFilled / KoahAdNoFill / KoahAdError, all exported. The format field is gone.

const result = await koah.requestAd({ adContext, cacheKey })
if (result.filled) {
  // render the slot
}

Preview formats

KoahAdSize is removed, and KoahPreviewFormat values are now the opaque render formats — update requestPreviewAd call sites and sample-ad fixtures (koahSampleAds.* use the same formats):

0.x1.0
cardTextcardTextMd
cardImagecardImageMd
pollpollMd
expandableexpandableMd
rabbitHoleRemoved
—pollCtaMd (new)

Install 1.0

Install the stable release:

npm install --save-exact koah-react-native@1.0.1

Need help upgrading? Email support@koahlabs.com.

Was this helpful?