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.
1.0 is a hard break with no compatibility shims. Apps on 0.x keep working against the 0.x releases, but upgrading the package requires the code changes on this page. Most call sites change only a few lines — or copy the prompt below and let a coding agent migrate for you.
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
| Aspect | 0.x | 1.0 |
|---|---|---|
| Initialization | <KoahProvider publisherId="..." debug={...} options={{ baseUrl }}> | Koah.init({ publisherId, logLevel?, baseUrl? }) at module scope, then <KoahProvider client={koah}> |
| Logging | debug: boolean | logLevel: KoahLogLevel (NONE / ERROR / WARNING / INFO / DEBUG) |
| Ad content | adContext optional, or legacy props (question / response / messageId / conversationId / isResponseReady, feed text / source / description) | adContext required on KoahTextAdComponent / KoahFeedAdComponent. Legacy props removed. |
| Sizing | overrideMaxWidth / overrideMaxHeight (dp), widthBehavior: "fill" | "wrap", deprecated size | width / height: KoahAxisSize (fixed(dp) / range({ min, max }) / fill()); omit an axis to hug content |
| Cached slot | <KoahCachedAdComponent messageId={...}> | <KoahCachedAdComponent cacheKey={...}> (rename only) |
| Imperative fetch | Koah.process, generateTextAd, prefetch, resolveAd, cancelPrefetch | koah.requestAd({ adContext, cacheKey }), prefetchAd(...), cancelPrefetchAd(cacheKey) |
| Hooks | useKoahAd, useKoahRequestAd | Removed. Render via the components; fetch via koah.requestAd / prefetchAd. |
| Result | { filled, format?, fromCache } | Discriminated union on kind: "filled" / "noFill" / "error" (no format) |
| Lifecycle callbacks | didReceiveAd, shouldGenerateAd | onEvent: (event: KoahEvent) => void on every component (onFill / onNoFill remain on the feed component) |
| Errors | Exported KoahError class | Removed — the SDK throws native Error types |
| Poll tracking | koah.trackPollVoted(queryExternalId) | Removed — poll votes are recorded automatically |
| Preview formats | KoahAdSize + KoahPreviewFormat.cardText, ... | KoahAdSize removed; KoahPreviewFormat.cardTextMd, ... |
The default width behavior changed. In 0.x a bare component stretched to
fill the parent's width (widthBehavior: "fill" was the default). In 1.0 an
unbounded axis hugs the content's natural width, so every default call
site renders narrower with no code change. Pass
width={KoahAxisSize.fill()} to restore the 0.x default.
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.
If you passed options: { baseUrl } in 0.x, baseUrl is now a top-level
field on the config: Koah.init({ publisherId, baseUrl }). The KoahOptions
type is gone.
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}
/>
shouldGenerateAd is removed — gate rendering of the component (or the
adContext value you build) yourself. didReceiveAd is removed — listen for
event.kind === "adServed" on the new onEvent callback instead.
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"→ omitwidth(hugging content is the new default).- The deprecated
sizeprop is removed with no direct replacement — omit both axes, or passrangebounds matching your slot.
A served ad that can't fit a forced or capped axis now renders nothing (and
bills no impression) instead of clipping, emitting KoahEvent.slotTooSmall
through onEvent. In 0.x, a slot below the 220dp minimum width removed the
component and logged an error; that clamp is gone.
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.x | 1.0 |
|---|---|
cardText | cardTextMd |
cardImage | cardImageMd |
poll | pollMd |
expandable | expandableMd |
rabbitHole | Removed |
| — | 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.