From 70eb1c3259460df4d0f5479e5194a3d037e27431 Mon Sep 17 00:00:00 2001 From: BlackBond06 Date: Thu, 31 Aug 2023 16:24:18 +0100 Subject: [PATCH 1/3] Fixed missing dependency issue in library component --- src/components/Library/Library.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Library/Library.jsx b/src/components/Library/Library.jsx index 97d468b..087543e 100644 --- a/src/components/Library/Library.jsx +++ b/src/components/Library/Library.jsx @@ -334,7 +334,7 @@ export default function Library({ filter }) { }; filteredRow(); - }, [filter]); + }, [filter, myRows]); useEffect(() => { fetchBooksFromDB(); From 40a9066da7ff9a3535538458da33f9fdf60228b9 Mon Sep 17 00:00:00 2001 From: BlackBond06 Date: Thu, 31 Aug 2023 17:11:19 +0100 Subject: [PATCH 2/3] Clean up useEffect dependencies when page unmounts --- src/components/Library/Library.jsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/components/Library/Library.jsx b/src/components/Library/Library.jsx index 087543e..2435b13 100644 --- a/src/components/Library/Library.jsx +++ b/src/components/Library/Library.jsx @@ -49,7 +49,7 @@ import axios from 'axios'; // ]; -export default function Library({ filter }) { +export default function Library({ filter, setFilter }) { const [myRows, setMyRows] = useState([]); const [visibleContent, setVisibleContent] = useState(-1); const [showSnackBar, handleSnackBar] = useState(false); @@ -332,8 +332,11 @@ export default function Library({ filter }) { setMyRows(myRows); } }; - filteredRow(); + return () => { + setMyRows([]); + setFilter(''); + }; }, [filter, myRows]); useEffect(() => { @@ -1021,4 +1024,5 @@ export default function Library({ filter }) { Library.propTypes = { filter: PropTypes.string, + setFilter: PropTypes.func, }; From 5d71d4c92192cc19aad2bc6b75fea48c8e425bd6 Mon Sep 17 00:00:00 2001 From: BlackBond06 Date: Thu, 31 Aug 2023 17:13:08 +0100 Subject: [PATCH 3/3] Add setFilter prop to libraray component --- src/pages/Home/Home.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/Home/Home.jsx b/src/pages/Home/Home.jsx index 71441c3..af4b673 100644 --- a/src/pages/Home/Home.jsx +++ b/src/pages/Home/Home.jsx @@ -103,7 +103,7 @@ function Home() { - +