List Rendering With Stable Keys
ReactJS
Medium
7 views
Problem Description
Render a topic list and use stable keys instead of index.
Output Format
Render a React component.
Constraints
Use key from data like id or slug.
Official Solution
import React from 'react';
const topics = [
{ id: 'html', name: 'HTML' },
{ id: 'css', name: 'CSS' },
{ id: 'react', name: 'React' }
];
export default function App() {
return (
<ul style={{ padding: 16 }}>
{topics.map((t) => (
<li key={t.id}>{t.name} on meetcode</li>
))}
</ul>
);
}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!