-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: 검색어와 100% 일치하는 데이터가 있는 경우 라우팅하는 커스텀 훅 분리(#120)
- Loading branch information
Showing
2 changed files
with
23 additions
and
10 deletions.
There are no files selected for viewing
13 changes: 3 additions & 10 deletions
13
src/components/search/searchBodySection/SearchBodySection.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { useRouter } from 'next/navigation'; | ||
import { useEffect } from 'react'; | ||
|
||
interface UseDetermineDirectRouterProps { | ||
kind: 'searchResult' | 'searchResultList'; | ||
searchKeyword: string; | ||
} | ||
|
||
const useDetermineDirectRouter = ({ kind, searchKeyword }: UseDetermineDirectRouterProps) => { | ||
const router = useRouter(); | ||
|
||
useEffect(() => { | ||
if (kind === 'searchResult') { | ||
const encodedTitle = encodeURIComponent(searchKeyword); | ||
router.push(`viewer?title=${encodedTitle}`); | ||
} | ||
}, [kind, router, searchKeyword]); | ||
}; | ||
|
||
export default useDetermineDirectRouter; |