Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

술 상세페이지 진입시 히스토리에 추가 #64

Merged
Prev Previous commit
Next Next commit
New : 위키 디테일로 이동하는 함수 Hooks 으로 변경
jobkaeHenry committed Dec 1, 2023
commit d865c25c1cb1402b97c5107a53f2228c8277ae7b
27 changes: 27 additions & 0 deletions client/src/hooks/wiki/usePushToWikiDetail.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { AlcoholDetailInterface } from "@/types/alcohol/AlcoholInterface";
import { useRouter } from "next/navigation";
import { useCallback } from "react";
import useSearchHistory from "../searchHistory/useSearchHistory";
import { ALCOHOL_SEARCH_HISTORY } from "@/const/localstorageKey";
import { WIKI_DETAIL } from "@/const/clientPath";
/**
* 검색히스토리에 해당 술을 남기고, 디테일페이지로 이동시키는 함수를 리턴하는 훅
* @returns 해당 callback함수
*/
const usePushToWikiDetail = () => {
const { add: addToSearchHistory } = useSearchHistory(ALCOHOL_SEARCH_HISTORY);
const router = useRouter();
/**
* 검색히스토리에 해당 술을 남기고, 디테일페이지로 이동시키는 함수를 리턴하는 함수
*/
const onClickElementHandler = useCallback(
({ alcoholName, alcoholNo }: AlcoholDetailInterface) => {
addToSearchHistory(alcoholName);
router.push(WIKI_DETAIL(String(alcoholNo)));
},
[addToSearchHistory]
);
return onClickElementHandler;
};

export default usePushToWikiDetail;