mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-26 05:16:41 +07:00
removed messages reducer
This commit is contained in:
parent
82308d2a91
commit
5849e68258
61 changed files with 314 additions and 898 deletions
17
src/hooks/messages/useMessages.ts
Normal file
17
src/hooks/messages/useMessages.ts
Normal file
|
@ -0,0 +1,17 @@
|
|||
import useSWR from 'swr';
|
||||
import { API } from '~/constants/api';
|
||||
import { apiGetUserMessages } from '~/api/messages';
|
||||
import { IMessage } from '~/redux/types';
|
||||
|
||||
const getKey = (username: string): string | null => {
|
||||
return username ? `${API.USER.MESSAGES}/${username}` : null;
|
||||
};
|
||||
export const useMessages = (username: string) => {
|
||||
const { data, isValidating } = useSWR(getKey(username), async () =>
|
||||
apiGetUserMessages({ username })
|
||||
);
|
||||
|
||||
const messages: IMessage[] = data?.messages || [];
|
||||
|
||||
return { messages, isLoading: !data && isValidating };
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue