Skip to content

Commit

Permalink
#21 Feat: useUserInterestsQuery 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
yunseul-dev committed Dec 7, 2023
1 parent eb176bd commit 6d49600
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/hooks/queries/useUserInterestsQuery.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import axios from 'axios';
import { useRecoilValue } from 'recoil';
import { useQuery } from '@tanstack/react-query';
import userState from '../../recoil/atom/userState';

const fetchData = async sortOption => {
const res = await axios.get(`/users/profile/popupLike/${sortOption}`, { withCredentials: true });
return res.data;
};

const staleTime = 1000 * 3;

const useUserInterestsQuery = sortOption => {
const email = useRecoilValue(userState);

const query = useQuery({
queryKey: ['@UserInterests', email, sortOption],
queryFn: () => fetchData(sortOption),
staleTime,
});

return { ...query, userInterests: query.data };
};

export default useUserInterestsQuery;

0 comments on commit 6d49600

Please sign in to comment.