Skip to content

Commit

Permalink
refactor(usePreviousPage): 필요없는 state 삭제 및 그 전 페이지만 저장하도록 수정
Browse files Browse the repository at this point in the history
- 그전 페이지만 알면되므로 객체로 저장할 필요가 없고, 그전 페이지를 state로 관리할 필요가 없기에 수정했습니다.
  • Loading branch information
0jenn0 committed Sep 25, 2024
1 parent ef79495 commit 55dbc7f
Showing 1 changed file with 1 addition and 14 deletions.
15 changes: 1 addition & 14 deletions frontend/src/hooks/usePreviousPage.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,13 @@
import { useEffect, useState } from "react";
import { useLocation, useNavigate } from "react-router-dom";

import { ROUTE_PATHS_MAP } from "@constants/route";

interface PreviousPages {
[key: string]: string;
}

const usePreviousPage = () => {
const navigate = useNavigate();
const location = useLocation();
const [previousPages, setPreviousPages] = useState<PreviousPages>({});

useEffect(() => {
setPreviousPages((prev) => ({
...prev,
[location.pathname]: document.referrer,
}));
}, [location]);
const previousPage = document.referrer;

const goBack = () => {
const previousPage = previousPages[location.pathname];
const currentPage = location.pathname;
const isPreviousPageMy = previousPage?.includes(ROUTE_PATHS_MAP.my);
const isCurrentPageLogin = currentPage.includes(ROUTE_PATHS_MAP.login);
Expand Down

0 comments on commit 55dbc7f

Please sign in to comment.