ReactJS Program to Card With Children Slot with Explanation
ReactJS
Easy
Component Design
17 views
1 min read
87 words
This problem helps you practice core ReactJS fundamentals in a practical way. It builds intuition around children, card, component. Let’s break it down step by step so you can implement it confidently.
Problem Statement
Make a Card component that accepts children and keeps the same look everywhere.
Input Format
No input.
Output Format
Render a React component.
Constraints
Use children prop for composition.
Code Solution
This explanation is written for learning purposes and to help beginners understand the concept clearly.
import React from 'react';
export function Card({ title, children }) {
return (
<section style={{ border: '1px solid #eee', borderRadius: 14, padding: 14, width: 360 }}>
<h2 style={{ margin: '0 0 8px 0' }}>{title}</h2>
<div>{children}</div>
</section>
);
}
export default function App() {
return (
<Card title='meetcode'>
<p style={{ margin: 0 }}>Small questions. Daily practice.</p>
<a href='#' style={{ display: 'inline-block', marginTop: 10, color: '#0a58ca' }}>Open topics</a>
</Card>
);
}
Output Example
No sample I/O is provided for this question.
Common Mistakes
- Misreading input/output format.
- Not handling constraints and edge cases.
- Off-by-one errors in loops.
- Forgetting to reset variables between test cases (if any).
Solution Guide
Problem
Make a Card component that accepts children and keeps the same look everywhere.
Input / Output
Output
Render a React component.
Constraints
Use children prop for composition.
Details
Common Mistakes
- Misreading input/output format.
- Not handling constraints and edge cases.
- Off-by-one errors in loops.
- Forgetting to reset variables between test cases (if any).
Official Solution
import React from 'react';
export function Card({ title, children }) {
return (
<section style={{ border: '1px solid #eee', borderRadius: 14, padding: 14, width: 360 }}>
<h2 style={{ margin: '0 0 8px 0' }}>{title}</h2>
<div>{children}</div>
</section>
);
}
export default function App() {
return (
<Card title='meetcode'>
<p style={{ margin: 0 }}>Small questions. Daily practice.</p>
<a href='#' style={{ display: 'inline-block', marginTop: 10, color: '#0a58ca' }}>Open topics</a>
</Card>
);
}
Solutions (0)
No solutions submitted yet. Be the first!