Files
ncd-fe/src/queries/trends.ts
marcin mikołajczak 0fc8a2993f More work on pl-api migration
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
2024-08-06 23:27:32 +02:00

31 lines
677 B
TypeScript

import { useQuery } from '@tanstack/react-query';
import { fetchTrendsSuccess } from 'soapbox/actions/trends';
import { useAppDispatch, useClient } from 'soapbox/hooks';
import type { Tag } from 'pl-api';
const useTrends = () => {
const dispatch = useAppDispatch();
const client = useClient();
const getTrends = async() => {
const data = await client.trends.getTrendingTags();
dispatch(fetchTrendsSuccess(data));
return data;
};
const result = useQuery<ReadonlyArray<Tag>>({
queryKey: ['trends'],
queryFn: getTrends,
placeholderData: [],
staleTime: 600000, // 10 minutes
});
return result;
};
export { useTrends as default };