bigbuffet-rw/app/soapbox/hooks/useGroups.ts

24 lines
533 B
TypeScript
Raw Normal View History

2023-03-09 09:21:27 -08:00
import { useEffect } from 'react';
import { useEntities } from 'soapbox/entity-store/hooks';
import { normalizeGroup } from 'soapbox/normalizers';
import type { Group } from 'soapbox/types/entities';
function useGroups() {
const result = useEntities<Group>(['Group', ''], '/api/v1/groups');
const { entities, isLoading, fetchEntities } = result;
useEffect(() => {
if (!isLoading) {
fetchEntities();
}
}, []);
return {
...result,
groups: entities.map(normalizeGroup),
};
}
export { useGroups };