Skip to content

Commit

Permalink
fix: 무한스크롤 미반영으로 캐시 삭제
Browse files Browse the repository at this point in the history
  • Loading branch information
a-honey committed Feb 27, 2024
1 parent 03a0d6e commit c7b0d26
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/components/organisms/FridgeBoard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ const FridgeBoard: React.FC = () => {
handleTabNameChange={handleTabNameChange}
/>
<div className="flex flex-col w-full gap-[24px]">
{ingredients?.pages.map((page) =>
page.content && page.content.length > 0 ? (
page.content.map((ingredient) => (
{ingredients?.pages.map(({ content }) =>
content && content.length > 0 ? (
content.map((ingredient) => (
<IngredientItemBox
key={ingredient.ingredientDetailId}
data={ingredient}
Expand Down
4 changes: 3 additions & 1 deletion src/components/organisms/IngredientModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import type { PostIngredientBodyType } from '@/hooks/queries/fridge/usePostIngre
import { useRouter } from 'next/router';
import usePutIngredientById from '@/hooks/queries/fridge/usePutIngredientById';
import axiosInstance from '@/api/axiosInstance';
import { queryClient } from '@/pages/_app';

const IngredientModal: React.FC<{
id: number;
Expand All @@ -47,8 +48,9 @@ const IngredientModal: React.FC<{

const onSuccess = () => {
toggleIsOpenIngredientModal();
ingredientsRefetch();
showToast('식자재 추가가 완료되었습니다.', 'success');
ingredientsRefetch();
queryClient.invalidateQueries({ queryKey: ['my_fridge'] });
};

const postIngredient = usePostIngredient(
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/queries/fridge/useGetFridgeContentById.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ const useGetFridgeContentById = ({
sort: LocationEnum;
id: number;
}) => {
return useBaseInfiniteQuery<FridgeContentType[]>({
const data = useBaseInfiniteQuery<FridgeContentType[]>({
queryKey: queryKeys.MY_FRIDGE_CONTENT(id, sort),
url: `/ingrs/detail/refrig/${id}`,
params: { location: sort },
});
return data;
};

export default useGetFridgeContentById;
1 change: 0 additions & 1 deletion src/hooks/queries/fridge/usePostFridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ interface PostFridgeBodyType {

const usePostFridge = () => {
const onSuccess = (data: PostFridgeBodyType) => {
console.log(data);
void queryClient.invalidateQueries();
};
return useBaseMutation<PostFridgeBodyType>(
Expand Down
7 changes: 5 additions & 2 deletions src/hooks/queries/useBaseInfiniteQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,12 @@ export const useBaseInfiniteQuery = <T>({

return useInfiniteQuery({
queryKey,
queryFn: async (context: QueryFunctionContext<QueryKey, number>) =>
await fetchData<T>(context),
queryFn: async (context: QueryFunctionContext<QueryKey, number>) => {
const data = await fetchData<T>(context);
return data;
},
initialPageParam: INITIAL_PAGE_PARAM,
getNextPageParam: (res) => getNextOffset<T>(res),
staleTime: 0,
});
};
1 change: 1 addition & 0 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const queryClient = new QueryClient({
defaultOptions: {
queries: {
staleTime: 0,
gcTime: 0,
retry: false,
refetchOnWindowFocus: false,
},
Expand Down

0 comments on commit c7b0d26

Please sign in to comment.