Careeroza
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
| Way | Example |
|---|---|
| CSS file + className | import "./Card.css" and className="card" |
| CSS Modules (scoped) | import s from "./Card.module.css" and className={s.card} |
| Inline style object | style={{ padding: 10 }} |
| Utility CSS | Tailwind: className="p-4 rounded" |
| CSS-in-JS | styled-components, Emotion |