feat: add useLazyApps hook
This commit is contained in:
29
packages/web/src/hooks/useLazyApps.js
Normal file
29
packages/web/src/hooks/useLazyApps.js
Normal file
@@ -0,0 +1,29 @@
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
|
||||
import api from 'helpers/api';
|
||||
|
||||
export default function useLazyApps({
|
||||
appName,
|
||||
onSuccess,
|
||||
abortControllerRef,
|
||||
}) {
|
||||
const query = useMutation({
|
||||
mutationFn: async ({ payload, signal }) => {
|
||||
abortControllerRef.current = new AbortController();
|
||||
|
||||
const { data } = await api.get('/v1/apps', {
|
||||
params: { name: appName },
|
||||
signal: abortControllerRef.current.signal,
|
||||
});
|
||||
|
||||
if (abortControllerRef.current.signal.aborted) {
|
||||
return;
|
||||
}
|
||||
|
||||
return data;
|
||||
},
|
||||
onSuccess,
|
||||
});
|
||||
|
||||
return query;
|
||||
}
|
Reference in New Issue
Block a user