mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 04:46:40 +07:00
refactored hooks directory
This commit is contained in:
parent
efa3ba902d
commit
f76a5a4798
106 changed files with 122 additions and 144 deletions
16
src/hooks/node/useGetNodeRelated.ts
Normal file
16
src/hooks/node/useGetNodeRelated.ts
Normal file
|
@ -0,0 +1,16 @@
|
|||
import { INode } from '~/redux/types';
|
||||
import useSWR from 'swr';
|
||||
import { ApiGetNodeRelatedResult } from '~/redux/node/types';
|
||||
import { API } from '~/constants/api';
|
||||
import { useCallback } from 'react';
|
||||
import { apiGetNodeRelated } from '~/redux/node/api';
|
||||
|
||||
export const useGetNodeRelated = (id?: INode['id']) => {
|
||||
const { data, isValidating, mutate } = useSWR<ApiGetNodeRelatedResult>(API.NODE.RELATED(id), () =>
|
||||
apiGetNodeRelated({ id })
|
||||
);
|
||||
|
||||
const refresh = useCallback(() => mutate(data, true), [data, mutate]);
|
||||
|
||||
return { related: data?.related, isLoading: isValidating && !data, refresh };
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue