1- import { Link , type LinkProps } from 'react-router' ;
1+ import { type LinkProps , useNavigate } from 'react-router' ;
22
33import {
44 CoinWithIconAndName ,
@@ -9,48 +9,51 @@ import { formatCurrencyKR } from '~/shared/utils';
99
1010export type CoinListItemProps = {
1111 to : LinkProps [ 'to' ] ;
12+ onClick ?: ( ) => void ;
1213} & CoinWithIconAndNameProps ;
1314
1415export default function CoinListItem ( {
1516 name,
1617 ticker,
1718 coinIcon : CoinIcon ,
1819 to,
20+ onClick,
1921} : Readonly < CoinListItemProps > ) {
22+ const navigate = useNavigate ( ) ;
2023 const currentPriceData = useCurrentPrice ( ticker ) ;
2124 const isBull = currentPriceData && currentPriceData . changeRate > 0 ;
2225 const formatedPrice = `${ formatCurrencyKR (
2326 + ( currentPriceData ?. currentPrice ?? 0 ) . toFixed ( 2 ) ,
2427 ) } 원`;
2528
29+ const handleClickCoinItem = async ( ) => {
30+ onClick ?.( ) ;
31+ await navigate ( to ) ;
32+ } ;
33+
2634 return (
27- < Link to = { to } className = "block px-2" >
28- < button
29- type = "button"
30- className = "flex w-[max(300px,100%)] cursor-pointer items-center py-1"
31- >
32- < div className = "flex-1" >
33- < CoinWithIconAndName
34- name = { name }
35- ticker = { ticker }
36- coinIcon = { CoinIcon }
37- />
38- </ div >
39- < div className = "flex-1 text-right text-sm" >
40- < span className = { isBull ? 'text-red-600' : 'text-blue-700' } >
41- { formatedPrice }
42- </ span >
43- </ div >
44- < div className = "flex-1 text-right text-sm" >
45- < span className = { isBull ? 'text-red-600' : 'text-blue-700' } >
46- { ( currentPriceData ?. changeRate ?? 0 ) . toFixed ( 2 ) } %
47- </ span >
48- </ div >
49- < div className = "flex-1 text-right text-sm" >
50- { /* TODO: 거래량 API가 나오면 추가할 것 */ }
51- < span > { 0 } </ span >
52- </ div >
53- </ button >
54- </ Link >
35+ < button
36+ type = "button"
37+ className = "flex w-[max(300px,100%)] cursor-pointer items-center py-1"
38+ onClick = { handleClickCoinItem }
39+ >
40+ < div className = "flex-1" >
41+ < CoinWithIconAndName name = { name } ticker = { ticker } coinIcon = { CoinIcon } />
42+ </ div >
43+ < div className = "flex-1 text-right text-sm" >
44+ < span className = { isBull ? 'text-red-600' : 'text-blue-700' } >
45+ { formatedPrice }
46+ </ span >
47+ </ div >
48+ < div className = "flex-1 text-right text-sm" >
49+ < span className = { isBull ? 'text-red-600' : 'text-blue-700' } >
50+ { ( currentPriceData ?. changeRate ?? 0 ) . toFixed ( 2 ) } %
51+ </ span >
52+ </ div >
53+ < div className = "flex-1 text-right text-sm" >
54+ { /* TODO: 거래량 API가 나오면 추가할 것 */ }
55+ < span > { 0 } </ span >
56+ </ div >
57+ </ button >
5558 ) ;
5659}
0 commit comments