Last active
November 10, 2024 19:29
-
-
Save yukikim/5dad9daa5862745f6f7d229422d41b0b to your computer and use it in GitHub Desktop.
[tsx]配列を map でレンダリング
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
import React from 'react'; | |
interface Item { | |
id: number; | |
name: string; | |
} | |
const MyComponent: React.FC = () => { | |
// 配列データを定義 | |
const items: Item[] = [ | |
{ id: 1, name: 'Item 1' }, | |
{ id: 2, name: 'Item 2' }, | |
{ id: 3, name: 'Item 3' } | |
]; | |
return ( | |
<div> | |
<h1>Items List</h1> | |
<ul> | |
{/* map を使って配列をループし、リストアイテムとして表示 */} | |
{items.map((item) => ( | |
<li key={item.id}>{item.name}</li> | |
))} | |
</ul> | |
</div> | |
); | |
}; | |
export default MyComponent; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment