Performance: Exporting and importing components
This concept affects the bundle size and initial load time by controlling how components are included and shared in the app.
export function SmallComponent() { return <div>Small Component</div>; } // Import only what is needed import { SmallComponent } from './SmallComponent';
export default function BigComponent() { return <div>Big Component</div>; } // Importing everything import BigComponent from './BigComponent';
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Default export importing whole module | No extra DOM nodes | No extra reflows | No direct paint cost | [X] Bad |
| Named export importing only needed components | No extra DOM nodes | No extra reflows | No direct paint cost | [OK] Good |
App is rendered?// Button.js
export function Button() { return <button>Click</button>; }// App.js
import { Button } from './Button';
export default function App() { return <div><Button /></div>; }import Button from './Button';Button.js contains:export function Button() { return <button>Click</button>; }Widgets.js:export function WidgetA() { return <div>A</div>; }
export function WidgetB() { return <div>B</div>; }Dashboard.js to use them?Pass the test and this pattern moves unknown