Keyed Fragment List
ReactJS
Hard
6 views
Problem Description
Render a list where each item outputs two lines using a keyed Fragment.
Output Format
Render a React component.
Constraints
Use React.Fragment with a key.
Official Solution
import React from 'react';
const lessons = [
{ id: 'l1', title: 'React basics', note: 'Components and props' },
{ id: 'l2', title: 'Hooks', note: 'State and effects' },
{ id: 'l3', title: 'Forms', note: 'Controlled inputs' }
];
export default function App() {
return (
<div style={{ padding: 16 }}>
{lessons.map((l) => (
<React.Fragment key={l.id}>
<strong>{l.title}</strong>
<div style={{ color: '#555', marginBottom: 10 }}>{l.note} on meetcode</div>
</React.Fragment>
))}
</div>
);
}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!