mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-24 20:36:40 +07:00
16 lines
609 B
TypeScript
16 lines
609 B
TypeScript
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 };
|
|
};
|