ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

25.01.01 Today I Learned๐Ÿ’ก

1. ์ธ๋ฑ์Šค ์‹œ๊ทธ๋‹ˆ์ฒ˜ VS Record<key, value>

2. ์ •๊ทœํ‘œํ˜„์‹


์ธ๋ฑ์Šค ์‹œ๊ทธ๋‹ˆ์ฒ˜ VS Record<key, value>

 

  • ์ธ๋ฑ์Šค ์‹œ๊ทธ๋‹ˆ์ฒ˜
    • ์•„์ดํ…œ์˜ ๋™์  ์ˆซ์ž๋“ค์„ key๋กœ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด ๋™์  ํƒ€์ž…์„ ๋”ฐ๋กœ ์ง€์ •
    • Item์˜ value์— ์ ‘๊ทผํ•  ๋•Œ key๊ฐ€ ์ธ์‹์ด ๋˜์ง€ ์•Š์•„ ๊ณค๋ž€ํ•œ ์ƒํ™ฉ
export type Item = {
  name: string;
  plaintext: string;
  image: { full: string };
  gold: { total: number };
  stats: { FlatMovementSpeedMod: number };
};

// ๋™์  key (1001, 1002...)
export type ItemResponse = {
  data: { [key: string]: Item };
};


// ์•„๋ž˜์™€ ๊ฐ™์ด ์ž‘๋™ํ•จ
export type Item = {
  data: {
    [key: string]: {
      name: string;
      plaintext: string;
      image: { full: string };
      gold: { total: number };
      stats: { FlatMovementSpeedMod: number };
    };
  };
};

 

  • Record<key, value>
    • key ๋ฅผ ๋ฌธ์ž์—ด ๋ฆฌํ„ฐ๋Ÿด๋กœ ์ธ์‹
    • ๊ฐ์ฒด key๊ฐ’์— ์ ‘๊ทผํ•  ๋•Œ data. name์— ๋ฐ”๋กœ ์ ‘๊ทผ ๊ฐ€๋Šฅ
      ์ฐธ๊ณ  ๋ฌธ์„œ
export type ItemResponse = Record<string, Item>;

export type Item = {
  name: string;
  plaintext: string;
  image: { full: string };
  gold: { total: number };
  stats: { FlatMovementSpeedMod: number };
};

 

 

 

์ •๊ทœํ‘œํ˜„์‹

 

  • ์•„์ดํ…œ ๋ชฉ๋ก ์ค‘ ์ด๋ฆ„๊ณผ ์„ค๋ช…์— ํƒœ๊ทธ ๋ฐ @ ํฌํ•จ๋จ
  • ์ •๊ทœํ‘œํ˜„์‹ .replace๋ฅผ ํŽ˜์ด์ง€์—์„œ ์ง์ ‘ ์ ์šฉ
    • .replace(/<[^>]+>|@\w+@/g, "")

๐Ÿ‘‡๐Ÿป

// Card.tsx

...
<h2 className="title text-[25px]">
              {name.replace(/<[^>]+>|@\w+@/g, "")}
            </h2>
            <p className="text-emerald-50">
              {title.replace(/<[^>]+>|@\w+@/g, "")}
            </p>
            ...

 

๊ณต์ง€์‚ฌํ•ญ
์ตœ๊ทผ์— ์˜ฌ๋ผ์˜จ ๊ธ€
์ตœ๊ทผ์— ๋‹ฌ๋ฆฐ ๋Œ“๊ธ€
Total
Today
Yesterday
๋งํฌ
TAG
more
ยซ   2026/03   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
๊ธ€ ๋ณด๊ด€ํ•จ