Card With Children Slot

Card With Children Slot

Easy ReactJS Component Design 16 views
Explanation Complexity

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.

Input / Output Format

Input Format
No input.
Output Format
Render a React component.
Constraints
Use children prop for composition.

Examples

Input:
Output:
(React code)

Example Solution (Public)

ReactJS
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>
  );
}

Official Solution Code

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>
  );
}
Please login to submit solutions.
Editor
Output

                                        
Please login to submit solutions.