Skip to content

Commit

Permalink
fix: BestItemList useEffect cleanup 함수
Browse files Browse the repository at this point in the history
  • Loading branch information
codefug committed Jun 15, 2024
1 parent fcf5f1e commit fe1e2ea
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/widgets/BestItemList/ui/BestItemList.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState, useEffect } from "react";
import { useState, useEffect, useRef } from "react";
import { ItemCard } from "../../../entities/ItemCard/ui/ItemCard";
import { INITIAL_VALUE } from "../../../shared/constants/constants";

Expand All @@ -11,6 +11,7 @@ export const BestItemList = () => {
const [dataState, setDataState] = useState(INITIAL_VALUE);
const [items, setItems] = useState<TotalProductsData["list"] | null>(null);
const orderBy = "favorite";
const isMounted = useRef(false);

const getBestItems = async (options: BestItemListProps) => {
try {
Expand All @@ -37,7 +38,11 @@ export const BestItemList = () => {
};

useEffect(() => {
isMounted.current = true;
getBestItems({ pageSize: 4, orderBy });
return () => {
isMounted.current = false;
};
}, []);

return (
Expand Down

0 comments on commit fe1e2ea

Please sign in to comment.