refactor: rewrite useCurrentUser with RQ
This commit is contained in:
@@ -1,6 +1,18 @@
|
||||
import { useQuery } from '@apollo/client';
|
||||
import { GET_CURRENT_USER } from 'graphql/queries/get-current-user';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
|
||||
import api from 'helpers/api';
|
||||
|
||||
export default function useCurrentUser() {
|
||||
const { data } = useQuery(GET_CURRENT_USER);
|
||||
return data?.getCurrentUser;
|
||||
const query = useQuery({
|
||||
queryKey: ['currentUser'],
|
||||
queryFn: async ({ signal }) => {
|
||||
const { data } = await api.get(`/v1/users/me`, {
|
||||
signal,
|
||||
});
|
||||
|
||||
return data;
|
||||
},
|
||||
});
|
||||
|
||||
return query;
|
||||
}
|
||||
|
@@ -1,6 +1,8 @@
|
||||
import userAbility from 'helpers/userAbility';
|
||||
import useCurrentUser from 'hooks/useCurrentUser';
|
||||
|
||||
export default function useCurrentUserAbility() {
|
||||
const currentUser = useCurrentUser();
|
||||
return userAbility(currentUser);
|
||||
const { data: currentUser } = useCurrentUser();
|
||||
|
||||
return userAbility(currentUser?.data);
|
||||
}
|
||||
|
Reference in New Issue
Block a user