MCPcopy Create free account
hub / github.com/dailydotdev/apps / useAdQuery

Function useAdQuery

packages/shared/src/features/monetization/useAdQuery.ts:19–49  ·  view source on GitHub ↗
({
  queryKey,
  enabled = true,
  staleTime,
  placement,
  active,
}: UseAdQueryOptions)

Source from the content-addressed store, hash-verified

17}
18
19export const useAdQuery = ({
20 queryKey,
21 enabled = true,
22 staleTime,
23 placement,
24 active,
25}: UseAdQueryOptions) => {
26 const boostsEnabled = useFeature(featurePostBoostAds);
27 const consent = useAdMacroContext(enabled) ?? undefined;
28 const fetchOptions = useMemo(
29 () =>
30 resolveAdFetchOptions({
31 placement,
32 active,
33 boostsEnabled,
34 consent,
35 }),
36 [placement, active, boostsEnabled, consent],
37 );
38
39 return useQuery<Ad | null>({
40 // consent fingerprint so ads refetch when the user answers the CMP banner
41 queryKey: [...queryKey, consent?.gdprApplies, consent?.consentString ?? ''],
42 queryFn: () => fetchAdByPlacement(fetchOptions),
43 enabled,
44 staleTime,
45 refetchOnMount: false,
46 refetchOnReconnect: false,
47 refetchOnWindowFocus: false,
48 });
49};

Callers 4

SquadsDirectoryFeedFunction · 0.90
AdAsCommentFunction · 0.90
PostSidebarAdWidgetFunction · 0.90
CoverGridFunction · 0.90

Calls 4

useFeatureFunction · 0.90
useAdMacroContextFunction · 0.90
resolveAdFetchOptionsFunction · 0.90
fetchAdByPlacementFunction · 0.90

Tested by

no test coverage detected