ํฐ์คํ ๋ฆฌ ๋ทฐ
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, "")
- .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>
...

'Forntend > Trouble Shooting' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| [์ฌ๋๋ณ_Day8] Tanstack Query ์ด๊ธฐ ๋ก๋ฉ ์ฒ๋ฆฌ - initialData (0) | 2025.04.06 |
|---|---|
| [LoL info App] 0313 ํธ๋ฌ๋ธ์ํ (0) | 2025.03.17 |
| [/\/] fetch ์ต์ ์ ํ์์ฑ (0) | 2025.03.13 |
| vercel ๋ฐฐํฌ ์ค๋ฅ - ์๋ก๊ณ ์นจ 404: NON_FOUND (0) | 2025.02.09 |
| [Pokemon PJ_Day 3]Dynamic Route์ QueryString (0) | 2025.02.06 |