Skip to main content

BannerAd

import { BannerAd, type BannerAdProps } from 'nitro-ui-admob'
function BannerAd(props: BannerAdProps): ReactElement

A banner ad. Fixed sizes lay out at their ad size; anchoredAdaptive takes its laid-out width and reports its height. Layout props override the size-derived width and height. Guide: banner ads.

Props​

BannerAdProps extends NitroUI's SharedViewProps without children, so layout and the other shared view props apply.

PropTypeDescription
adUnitIdstringRequired. The AdMob ad unit ID. An empty string loads nothing.
sizeBannerAdSizeDefaults to anchoredAdaptive, which uses the laid-out width.
requestOptionsAdmobRequestOptionsTargeting for the ad requests. Changing its contents loads a new ad.
onAdLoaded(dimensions: BannerAdDimensions) => voidAn ad loaded, with its size.
onAdFailedToLoad(error: AdmobError) => voidAn ad request failed.
onAdImpression() => voidThe SDK recorded an impression.
onAdClicked() => voidThe SDK recorded a click.
onAdPaid(value: AdmobAdValue) => voidWith the estimated revenue of an impression.
onAdOpened() => voidThe ad opened an overlay over the app.
onAdClosed() => voidThe overlay opened by the ad was dismissed.
onSizeChange(dimensions: BannerAdDimensions) => voidWith the ad size before each request.

Types: BannerAdDimensions, AdmobError, AdmobAdValue.

BannerAdView​

import type { BannerAdView } from 'nitro-ui-admob'

The native view behind BannerAd, exported as a type. It loads an ad once adUnitId is set and, for adaptive sizes, laid out. It has the props above as properties, and:

MemberDescription
destroy()Stops ad requests, drops all callbacks and releases the native banner. The view stays mountable. BannerAd calls it on unmount.