bigbuffet-rw/app/soapbox/hooks/useGroups.ts
2023-03-09 11:21:27 -06:00

24 lines
No EOL
533 B
TypeScript

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 };