feat: introduce useLazyFlows with RQ

This commit is contained in:
Rıdvan Akca
2024-03-19 16:56:53 +03:00
parent 452f45cac6
commit ec87c7f21c
3 changed files with 70 additions and 43 deletions

View File

@@ -0,0 +1,30 @@
import * as React from 'react';
import api from 'helpers/api';
import { useMutation } from '@tanstack/react-query';
export default function useFlows({ flowName, page }, { onSuccess }) {
const abortControllerRef = React.useRef(new AbortController());
React.useEffect(() => {
abortControllerRef.current = new AbortController();
return () => {
abortControllerRef.current?.abort();
};
}, [flowName]);
const query = useMutation({
mutationFn: async () => {
const { data } = await api.get('/v1/flows', {
params: { name: flowName, page },
signal: abortControllerRef.current.signal,
});
return data;
},
onSuccess,
});
return query;
}