diff --git a/src/components/cards/MoreBooks.tsx b/src/components/cards/MoreBooks.tsx index 53c654b..641e3f6 100644 --- a/src/components/cards/MoreBooks.tsx +++ b/src/components/cards/MoreBooks.tsx @@ -10,21 +10,12 @@ export default function MoreBooks({ currentBookId }: ReleatedBooksType) { const { data, refetch } = useMoreBooks(); const moreBooks = useRefetchLocation(currentBookId, data, refetch); - // const moreBooks = data.filter((book: any) => { - // if (book.pathUrl === currentBookId) { - // refetch(); - // } - - // return book.pathUrl !== currentBookId; - // }); - return ( <> {moreBooks.map(({ id, title, authors, pathUrl }: CardType) => ( ( { @@ -13,11 +14,10 @@ export function useRefetchLocation(currentBookId, data, refetch) { setRelatedBooks(filteredBooks); - if (location.pathname !== previousPathname) { + if (pathname !== previousPathname) { refetch(); - setPreviousPathname(location.pathname); + setPreviousPathname(pathname); } - }, [data, currentBookId, location.pathname, refetch, previousPathname]); - + }, [data, currentBookId, pathname, refetch, previousPathname]); return relatedBooks; }