From af3f055bfdf96bd9a7ec29d9b155d7eca8010e5b Mon Sep 17 00:00:00 2001 From: Erik Arvidsson Date: Tue, 19 Mar 2024 12:39:52 +0100 Subject: [PATCH] fix: Navigo kept adding listeners (#19) Anytime the URL changed we added a new listener. This lead to confusion. --- client/src/app.tsx | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/client/src/app.tsx b/client/src/app.tsx index c40cd1e..17e816b 100644 --- a/client/src/app.tsx +++ b/client/src/app.tsx @@ -25,14 +25,18 @@ const App = ({ const [listID, setListID] = useState(''); const [showingShare, setShowingShare] = useState(false); - router.on('/list/:listID', match => { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const {data} = match!; - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const {listID} = data!; - setListID(listID); + useEffect(() => { + router.on('/list/:listID', match => { + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + const {data} = match!; + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + const {listID} = data!; + setListID(listID); + }); + return () => { + router.off('/list/:listID'); + }; }); - useEffect(() => { router.resolve(); }, []);