functionWrapper({ children }){return<div className="wrapper">{children}</div>;}
Example
functionCard({ children, title }){return(<section className="card"><h2>{title}</h2><div className="card-body">{children}</div></section>);}// Usage<Card title="Profile"><p>This content is passed as children.</p></Card>
Output
Renders a card wrapper around the paragraph.
Note children can be any renderable content: text, elements, arrays, or even functions (for render props).
children propwrapper componentpass childrennested contentslot pattern
Default Prop Values
Syntax
functionComponent({ propA = defaultValue }){...}
Example
functionBadge({ label ="Member", color ="gray"}){return(<span style={{ backgroundColor: color }}>{label}</span>);}// Uses defaults<Badge/>// Overrides<Badge label="Admin" color="crimson"/>
Output
First renders "Member" with gray background. Second renders "Admin" with crimson.
Note Use default parameter values in the destructuring rather than the legacy defaultProps static property, which is deprecated in React 19.
Note Composition via props is preferred over inheritance. Passing components as props gives you flexible "slot" patterns without tightly coupling parent and child.
Returns null when no message. Otherwise renders an alert with type prefix.
Note Returning null renders nothing. Watch out with &&: if the left side is 0, React renders "0" because it is a valid JSX child. Use Boolean(count) && <Component /> or count > 0 && <Component /> instead.
Note Keys must be stable, unique among siblings, and derived from data (like a database ID). Never use array index as key if the list order can change -- it causes subtle rendering bugs and broken state.
render listmap arraylist keyrender arraydynamic list
Fragments
Syntax
<React.Fragment>...</React.Fragment>// Short syntax<>...</>
Note Fragments let you group elements without adding extra DOM nodes. Use the long syntax <React.Fragment key={...}> when mapping a list, since the short syntax does not support the key attribute.
fragmentgroup elementsno wrapper divmultiple elementsadjacent elements