useAdkit()
Access the Adkit context from any component inside AdkitProvider. The primary use case is triggering a slot refresh after client-side navigation.
Overview
useAdkit() returns the context value provided by the nearest AdkitProvider. It throws if called outside a provider tree.
useAdkit() must be called inside a component that is a descendant of AdkitProvider. Using it without a provider throws an error.Return value
| Property | Type | Description |
|---|---|---|
| siteId | string | The site ID passed to the provider |
| refreshKey | number | Increments each time refresh() is called. Slots use this as a key to force remounting. |
| refresh | () => void | Clears all slot tracking state and forces every AdSlot to re-initialize. Use after SPA route changes where slots re-render on a new page. |
| mountedSlots | Set<string> | Set of currently mounted slot identities in the format siteId:slot |
| registerSlot | (identity: string) => boolean | Internal. Returns true if registration succeeded, false if this identity was already registered (duplicate). |
| unregisterSlot | (identity: string) => void | Internal. Called by AdSlot on unmount to free the identity. |
SPA refresh after navigation
In single-page applications, slots from a previous route may still be tracked by the provider when the user navigates to a new page. Calling refresh() clears that state so new impressions are counted correctly and duplicate-slot detection resets.
React Router
Render <AdRefresher /> once inside your router, at the same level as your route definitions.
Next.js App Router
Reading context values
Slot identity format
Slot identities in mountedSlots use the format siteId:slot. The identity is site-scoped, not page-scoped — the same slot name maps to the same identity regardless of which URL it appears on.