bigbuffet-rw/app/soapbox/queries/carousels.ts
2022-08-09 10:24:43 -05:00

29 lines
585 B
TypeScript

import { useQuery } from '@tanstack/react-query';
import { useApi } from 'soapbox/hooks';
type Avatar = {
account_id: string
account_avatar: string
username: string
}
export default function useCarouselAvatars() {
const api = useApi();
const getCarouselAvatars = async() => {
const { data } = await api.get('/api/v1/truth/carousels/avatars');
return data;
};
const result = useQuery<Avatar[]>(['carouselAvatars'], getCarouselAvatars, {
placeholderData: [],
});
const avatars = result.data;
return {
...result,
data: avatars || [],
};
}