Skip to content

Instantly share code, notes, and snippets.

@yukikim
Last active November 10, 2024 19:29
Show Gist options
  • Save yukikim/5dad9daa5862745f6f7d229422d41b0b to your computer and use it in GitHub Desktop.
Save yukikim/5dad9daa5862745f6f7d229422d41b0b to your computer and use it in GitHub Desktop.
[tsx]配列を map でレンダリング
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