"use client"; // 같은 시장 내 거래량/유동성 기준 관련 종목 8개. // /api/markets/related/{code} 응답을 좁은 list 카드로 렌더. import Link from "next/link"; import { useEffect, useState } from "react"; import { api, type RelatedResponse } from "../lib/api"; export function RelatedStocks({ code }: { code: string }) { const [data, setData] = useState(null); const [err, setErr] = useState(null); useEffect(() => { let alive = true; setErr(null); setData(null); api .related(code, 8) .then((r) => { if (alive) setData(r); }) .catch((e) => { if (alive) setErr(e instanceof Error ? e.message : String(e)); }); return () => { alive = false; }; }, [code]); if (err) return (
관련 종목 로딩 실패: {err}
); if (!data) return (
관련 종목 로딩 중…
); if (!data.items.length) return (
같은 시장({data.market}) 데이터가 아직 부족합니다.
); return (
관련 종목
{data.market} · 거래량 기준
    {data.items.map((m) => { const pct = m.pct_change; const tone = pct == null || pct === 0 ? "text-zinc-400" : pct > 0 ? "text-rose-400" : "text-sky-400"; return (
  • {m.name} {m.close != null ? m.close.toLocaleString(undefined, { maximumFractionDigits: 0 }) : "—"} {pct != null ? `${pct >= 0 ? "+" : ""}${pct.toFixed(2)}%` : ""}
  • ); })}
); }