Merge branch 'feat/inda-383-daily-stat' into 'main'
[ProtonMail-WebClient.git] / packages / components / hooks / useContactEmailsSortedByName.ts
blobe677cf98ec11faebe8bd41ea9eb5bde1968c66cd
1 import { useMemo } from 'react';
3 import { useContactEmails } from '@proton/mail/contactEmails/hooks';
4 import type { ContactEmail } from '@proton/shared/lib/interfaces/contacts/Contact';
6 const compareContactEmailByName = (a: ContactEmail, b: ContactEmail) => {
7     return a.Name.localeCompare(b.Name);
8 };
10 const useContactEmailsSortedByName = () => {
11     const [contactEmails, loading] = useContactEmails();
12     return useMemo(() => {
13         return [[...(contactEmails || [])].sort(compareContactEmailByName), loading] as const;
14     }, [contactEmails]);
17 export default useContactEmailsSortedByName;