Course contentsShow
← JavaScript
Lesson 1419 of 2,72331. ModulesFree lesson

Community Conventions

Explore common patterns: React components often use defaults, utility libraries prefer named exports.

Community Conventions

What you'll learn: How the JavaScript community typically decides between default and named exports in different contexts.

The Unwritten Rules

While JavaScript lets you choose freely between default and named exports, the community has developed informal patterns that make codebases more predictable. Following these conventions helps other developers instantly understand your module's structure.

React Components: Default by Default

React components almost always use default exports. This convention emerged because components are typically the single, primary thing a file exports:

// Button.js - typical React pattern
export default function Button({ label }) {
  return <button>{label}</button>;
}

// App.js
import Button from './Button';
import MyButton from './Button'; // easy renaming

The flexibility to rename on import matches how components are used—you might want PrimaryButton in one file and SubmitButton in another, even if importing the same component.

Utility Libraries: Named for Clarity

Utility modules and helper libraries prefer named exports because they typically export multiple functions:

// utils.js - typical utility pattern
export function formatDate(date) { /* ... */ }
export function validateEmail(email) { /* ... */ }
export function capitalize(str) { /* ... */ }

// importing
import { formatDate, validateEmail } from './utils';

Named exports make it clear exactly what you're pulling from a utility module and enable better tree-shaking.

Why These Conventions Matter

Following these patterns means other developers can glance at your import statement and immediately know what kind of module they're dealing with. A default import? Probably a component or class. Curly braces? Likely utilities or constants.

Key Takeaway: React components conventionally use default exports for flexibility, while utility libraries prefer named exports for clarity and tree-shaking—following these patterns makes your code more maintainable and predictable.