TossAds.destroyAll
Destroys all banner ad slots currently on the page, removing them from the DOM and releasing their resources. Use this for bulk cleanup on page transitions or component unmounts.
Signature
destroyAll is exposed as a member of the TossAds namespace object.
import { TossAds } from '@apps-in-toss/web-framework';
declare const TossAds: {
destroyAll: (() => void) & {
isSupported: () => boolean;
};
};
Parameters
None.
Returns
void— no return value.
Permission
No permission required — TossAds.destroyAll is not bound to a PermissionName. For the typical permission flow used by other namespaces, see Guides — Permissions pattern.
Examples
Minimal
import { TossAds } from '@apps-in-toss/web-framework';
TossAds.destroyAll();
Realistic — clean up all ad slots on page unmount
import { TossAds } from '@apps-in-toss/web-framework';
import { useEffect, useRef } from 'react';
const AD_GROUP_ID = 'ad-group-id-here';
function AdsPage() {
const bannerRef = useRef<HTMLDivElement>(null);
useEffect(() => {
if (!bannerRef.current) return;
if (!TossAds.initialize.isSupported()) return;
TossAds.initialize({});
TossAds.attachBanner(AD_GROUP_ID, bannerRef.current);
// Destroy all slots when the page unmounts
return () => {
TossAds.destroyAll();
};
}, []);
return <div ref={bannerRef} />;
}
Try it live
Open the Ads page in sdk-example and run the TossAds.destroyAll card to inspect the result.
Related APIs
TossAds.destroy— destroys a specific slot by ID.TossAds.attachBanner— attaches a banner ad to a DOM element.TossAds.initialize— initializes the TossAds SDK.
Related guides
- Guides — Ads integration pattern — lifecycle, cleanup, and environment guards in one place.
External references
@apps-in-toss/web-framework— SDK package. The actual exports are re-exported from@apps-in-toss/web-bridge.