Skip to main content

TossAds.destroy

Destroys a specific banner ad slot by ID, removing it from the DOM and releasing its resources. Use this when you need to remove a single slot; use TossAds.destroyAll for bulk removal.

Signature

destroy is exposed as a member of the TossAds namespace object.

import { TossAds } from '@apps-in-toss/web-framework';

declare const TossAds: {
destroy: ((slotId: string) => void) & {
isSupported: () => boolean;
};
};

Parameters

NameTypeRequiredDescription
slotIdstringThe slot ID to remove. Available from BannerSlotEventPayload.slotId in ad callbacks.

Returns

  • void — no return value.

Permission

No permission required — TossAds.destroy 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.destroy('slot-id-here');

Realistic — capture slot ID from callback and remove on demand

import { TossAds } from '@apps-in-toss/web-framework';
import { useEffect, useRef, useState } from 'react';

const AD_GROUP_ID = 'ad-group-id-here';

function AdBanner() {
const containerRef = useRef<HTMLDivElement>(null);
const [currentSlotId, setCurrentSlotId] = useState<string | null>(null);

useEffect(() => {
if (!containerRef.current) return;
if (!TossAds.attachBanner.isSupported()) return;

const { destroy } = TossAds.attachBanner(AD_GROUP_ID, containerRef.current, {
callbacks: {
onAdRendered: (payload) => {
setCurrentSlotId(payload.slotId);
},
},
});

return destroy;
}, []);

const handleRemove = () => {
if (currentSlotId) {
TossAds.destroy(currentSlotId);
setCurrentSlotId(null);
}
};

return (
<div>
<div ref={containerRef} />
<button type="button" onClick={handleRemove} disabled={!currentSlotId}>
Remove ad
</button>
</div>
);
}

Try it live

Open the Ads page in sdk-example to try ad-related APIs live.

Open in sdk-example

External references