refactor: rewrite useApp with RQ

This commit is contained in:
Rıdvan Akca
2024-03-05 17:35:22 +03:00
parent 5fe3546d2a
commit be62c09d06
2 changed files with 30 additions and 12 deletions

View File

@@ -1,12 +1,19 @@
import { useQuery } from '@apollo/client';
import { GET_APP } from 'graphql/queries/get-app';
export default function useApp(key) {
const { data, loading } = useQuery(GET_APP, {
variables: { key },
import { useQuery } from '@tanstack/react-query';
import api from 'helpers/api';
export default function useApp(appKey) {
const query = useQuery({
queryKey: ['app', appKey],
queryFn: async ({ payload, signal }) => {
const { data } = await api.get(`/v1/apps/${appKey}`, {
signal,
});
return data;
},
enabled: !!appKey,
});
const app = data?.getApp;
return {
app,
loading,
};
return query;
}