mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-26 05:16:41 +07:00
added useMemos to get data hooks
This commit is contained in:
parent
1904153bba
commit
d9feff085a
11 changed files with 49 additions and 19 deletions
|
@ -2,6 +2,7 @@ import useSWR from 'swr';
|
|||
import { API } from '~/constants/api';
|
||||
import { apiGetUserMessages } from '~/api/messages';
|
||||
import { IMessage } from '~/types';
|
||||
import { useMemo } from 'react';
|
||||
|
||||
const getKey = (username: string): string | null => {
|
||||
return username ? `${API.USER.MESSAGES}/${username}` : null;
|
||||
|
@ -11,7 +12,7 @@ export const useMessages = (username: string) => {
|
|||
apiGetUserMessages({ username })
|
||||
);
|
||||
|
||||
const messages: IMessage[] = data?.messages || [];
|
||||
const messages: IMessage[] = useMemo(() => data?.messages || [], [data]);
|
||||
|
||||
return { messages, isLoading: !data && isValidating };
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue