Skip to content

Commit

Permalink
Add useEffect cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
heptacode committed Jan 30, 2024
1 parent dcd6bde commit 07a5d76
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/pages/[projectId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Center, CircularProgress, Icon, IconButton } from '@chakra-ui/react';
import { useRouter } from 'next/router';
import { useEffect } from 'react';
import { MdMenu } from 'react-icons/md';
import { useCollectionStore } from '@/features/collections/useCollectionStore';
import { Sidebar } from '@/features/global/Sidebar';
import { useGlobalStore } from '@/features/global/useGlobalStore';
import { GoogleMap } from '@/features/maps/GoogleMap';
Expand All @@ -15,6 +16,8 @@ export default function Project() {
const router = useRouter();
const globalStore = useGlobalStore();
const projectStore = useProjectStore();
const collecionStore = useCollectionStore();

useProjectQuery({
onFetchError() {
router.replace('/');
Expand Down Expand Up @@ -50,6 +53,11 @@ export default function Project() {
router.replace('/');
}
}

return () => {
projectStore.setProjectId(null);
collecionStore.setCollectionId(null);
};
}, [router.query.projectId]);

return (
Expand Down

0 comments on commit 07a5d76

Please sign in to comment.