Skip to main content

Function: useTrending()

useTrending(params): UseQueryResult<{ cursor: string; hasMore: boolean; trending: object[]; window: "24h" | "7d" | "30d"; }, Error>

Defined in: web/lib/hooks/use-trending.ts:70

Fetches trending preprints based on view metrics.

Parameters

params

UseTrendingParams = {}

Query parameters (window, limit, cursor)

Returns

UseQueryResult<{ cursor: string; hasMore: boolean; trending: object[]; window: "24h" | "7d" | "30d"; }, Error>

Query result with trending preprints, loading state, and error

Remarks

Uses TanStack Query with a 1-minute stale time for near-real-time updates. Trending is calculated based on views within the specified time window.

Example

const { data, isLoading, error } = useTrending({ window: '7d', limit: 10 });

if (isLoading) return <TrendingSkeleton />;
if (error) return <ErrorMessage error={error} />;

return (
<TrendingList>
{data.trending.map((preprint) => (
<TrendingCard key={preprint.uri} preprint={preprint} />
))}
</TrendingList>
);

Throws

When the trending API request fails