Composition, Fragments and Styling

Composition with children

Example

Components can wrap other content through the special children prop.

function Card({ title, children }) {
  return (
    <div style={{ border: '1px solid #ccc', borderRadius: 8, padding: 10, marginBottom: 8 }}>
      <h3>{title}</h3>
      {children}
    </div>
  );
}

export default function App() {
  return (
    <>
      <Card title="Profile"><p>Asha, Frontend developer</p></Card>
      <Card title="Skills"><p>React, TypeScript</p></Card>
    </>
  );
}

Result

Ways to Style Components

WayExample
CSS file + classNameimport "./Card.css" and className="card"
CSS Modules (scoped)import s from "./Card.module.css" and className={s.card}
Inline style objectstyle={{ padding: 10 }}
Utility CSSTailwind: className="p-4 rounded"
CSS-in-JSstyled-components, Emotion