useFilteredAnnouncements
Filter a list of AnnouncementConfig by their `audience` prop. Bulk segment evaluation that is safe under dynamic lists.
Filter a list of AnnouncementConfig objects by their audience prop. Returns a new array containing only the announcements whose audience passes the current segmentation context.
Usage
import { useFilteredAnnouncements } from '@tour-kit/announcements';
function ChangelogList({ announcements }: { announcements: AnnouncementConfig[] }) {
const visible = useFilteredAnnouncements(announcements);
return (
<ul>
{visible.map((a) => (
<li key={a.id}>{a.title}</li>
))}
</ul>
);
}Signature
function useFilteredAnnouncements(
announcements: AnnouncementConfig[]
): AnnouncementConfig[]Audience evaluation rules
| Audience shape | Behavior |
|---|---|
undefined | Let through (always visible). |
AudienceCondition[] | Let through — forwarded to the scheduler, which re-checks against the provider's userContext prop. |
{ segment: string } | Evaluated here via useSegments. Filtered out if the segment is false. |
Only segment-shape audiences are filtered at this seam — array-shape audiences pass through because they require the provider's userContext, which the framework-agnostic scheduler owns. See the segmentation guide for the full evaluation pipeline.
Why bulk?
The hook reads all segments once at the top via useSegments() and reuses that map inside the filter callback. This is safe under dynamic announcement lists — never call useSegment (the single-segment hook) inside a .filter() body; that violates the rules of hooks.
Related
- evaluateAnnouncementAudience — underlying single-item evaluator
- Audience targeting — audience prop reference
- Segmentation guide
Ship onboarding, not config.
npm i @tour-kit/core is MIT and free. The Pro packages work unlicensed too — a one-time $99 license removes the production watermark when you ship.
MIT-licensed — no signup, no credit card. Pay once, only when you ship.
useAnnouncementsContext
Low-level hook returning the raw AnnouncementsProvider context — registered announcements, queue, queue config, and the full action surface
useResolvedText
Re-export of @tour-kit/core's useResolvedText for ergonomic in-package access. Resolves LocalizedText | ReactNode into a ReactNode.