Falytom logoFALYTOM
Games
ToolsUI ComponentsServicesProductsAbout
LoginSign Up
menu
  1. Home
  2. /Web Development
  3. /React
  4. /Component Organization
Your Progress0%
0 of 42 completed

React Topics

Getting Started

  • What is React?
  • React vs Vanilla JavaScript
  • Setting Up Your Environment
  • Your First React App

JSX Fundamentals

  • Introduction to JSX
  • JSX Expressions and Variables
  • Conditional Rendering
  • Lists and Keys
  • Styling in JSX

Components Basics

  • Function Components
  • Props
  • Children Prop
  • Props Destructuring
  • Component Composition

State Management

  • Introduction to State
  • useState Hook
  • State Updates and Re-renders
  • Multiple State Variables
  • State Best Practices

Events and Interactivity

  • Handling Events
  • Event Objects
  • Forms in React
  • Form Validation

Side Effects and Data

  • Introduction to useEffect
  • Data Fetching
  • Cleanup Functions
  • Dependency Arrays

Advanced Hooks

  • useRef Hook
  • useContext Hook
  • useMemo Hook
  • useCallback Hook

React Patterns

  • Custom Hooks
  • Higher-Order Components
  • Render Props Pattern

React Router

  • Introduction to React Router
  • Routes and Navigation
  • Dynamic Routes and Parameters

Best Practices

  • Component Organization
  • Performance Optimization
  • Error Handling
  • Testing React Components

Real World Project

  • Building a Complete App

Component Organization

File structure and project organization

As your React application grows, organization becomes critical. Where do you put components? How do you name files? What folder structure should you use? Good organization makes your code easier to understand, maintain, and scale. In this lesson, you'll learn proven patterns for organizing React projects, from small apps to large production codebases. Let's build maintainable React applications! šŸ“

Why Organization Matters

Poor organization leads to:

  • Difficulty finding files
  • Duplicate code
  • Inconsistent patterns
  • Hard to onboard new developers
  • Slower development
  • Technical debt

Good organization provides:

  • Clear structure everyone understands
  • Easy to find and modify code
  • Reusable components
  • Faster development
  • Easier testing
  • Better scalability

File Naming Conventions

Component Files

component-naming.txt
āœ… Recommended: PascalCase
Button.jsx
UserProfile.jsx
ProductCard.jsx
NavigationMenu.jsx

āœ… Also acceptable: PascalCase with extension
Button.tsx
UserProfile.tsx

āœ… For pages/routes: PascalCase or kebab-case
HomePage.jsx  or  home-page.jsx
AboutPage.jsx  or  about-page.jsx

āŒ Avoid:
button.jsx           // lowercase (hard to distinguish from non-components)
user-profile.jsx     // kebab-case for components (inconsistent)
userProfile.jsx      // camelCase (not standard for components)

Non-Component Files

other-naming.txt
āœ… Utilities and helpers: camelCase
formatDate.js
calculateTotal.js
validateEmail.js

āœ… Hooks: camelCase with "use" prefix
useAuth.js
useFetch.js
useLocalStorage.js

āœ… Constants: UPPER_SNAKE_CASE
API_ENDPOINTS.js
COLORS.js
CONFIG.js

āœ… Types/Interfaces (TypeScript): PascalCase
User.types.ts
Product.interface.ts
types.ts

āœ… Styles: Match component name
Button.css
Button.module.css
Button.styles.js

šŸ’” Naming Convention Rule

Simple rule:
• Components → PascalCase
• Everything else → camelCase
• Constants → UPPER_SNAKE_CASE

Consistency matters more than the specific convention!

Folder Structure Patterns

Pattern 1: Feature-Based Structure (Recommended)

feature-based.txt
src/
ā”œā”€ā”€ features/
│   ā”œā”€ā”€ auth/
│   │   ā”œā”€ā”€ components/
│   │   │   ā”œā”€ā”€ LoginForm.jsx
│   │   │   ā”œā”€ā”€ SignupForm.jsx
│   │   │   └── PasswordReset.jsx
│   │   ā”œā”€ā”€ hooks/
│   │   │   ā”œā”€ā”€ useAuth.js
│   │   │   └── useLogin.js
│   │   ā”œā”€ā”€ services/
│   │   │   └── authService.js
│   │   ā”œā”€ā”€ utils/
│   │   │   └── validation.js
│   │   └── index.js
│   │
│   ā”œā”€ā”€ products/
│   │   ā”œā”€ā”€ components/
│   │   │   ā”œā”€ā”€ ProductCard.jsx
│   │   │   ā”œā”€ā”€ ProductList.jsx
│   │   │   └── ProductDetail.jsx
│   │   ā”œā”€ā”€ hooks/
│   │   │   └── useProducts.js
│   │   └── index.js
│   │
│   └── user/
│       ā”œā”€ā”€ components/
│       │   ā”œā”€ā”€ UserProfile.jsx
│       │   └── UserSettings.jsx
│       ā”œā”€ā”€ hooks/
│       │   └── useUser.js
│       └── index.js
│
ā”œā”€ā”€ components/           # Shared/reusable components
│   ā”œā”€ā”€ ui/
│   │   ā”œā”€ā”€ Button.jsx
│   │   ā”œā”€ā”€ Input.jsx
│   │   ā”œā”€ā”€ Modal.jsx
│   │   └── Card.jsx
│   └── layout/
│       ā”œā”€ā”€ Header.jsx
│       ā”œā”€ā”€ Footer.jsx
│       └── Sidebar.jsx
│
ā”œā”€ā”€ hooks/               # Shared hooks
│   ā”œā”€ā”€ useLocalStorage.js
│   ā”œā”€ā”€ useDebounce.js
│   └── useWindowSize.js
│
ā”œā”€ā”€ utils/               # Shared utilities
│   ā”œā”€ā”€ formatDate.js
│   ā”œā”€ā”€ api.js
│   └── constants.js
│
ā”œā”€ā”€ pages/               # Page components
│   ā”œā”€ā”€ HomePage.jsx
│   ā”œā”€ā”€ AboutPage.jsx
│   └── DashboardPage.jsx
│
ā”œā”€ā”€ App.jsx
└── index.js

Benefits:
āœ… Related code grouped together
āœ… Easy to find feature-specific code
āœ… Clear separation of concerns
āœ… Easy to add/remove features
āœ… Scales well for large apps

Pattern 2: Type-Based Structure

type-based.txt
src/
ā”œā”€ā”€ components/
│   ā”œā”€ā”€ Button.jsx
│   ā”œā”€ā”€ Card.jsx
│   ā”œā”€ā”€ Header.jsx
│   ā”œā”€ā”€ Footer.jsx
│   ā”œā”€ā”€ LoginForm.jsx
│   ā”œā”€ā”€ ProductCard.jsx
│   └── UserProfile.jsx
│
ā”œā”€ā”€ hooks/
│   ā”œā”€ā”€ useAuth.js
│   ā”œā”€ā”€ useFetch.js
│   └── useProducts.js
│
ā”œā”€ā”€ pages/
│   ā”œā”€ā”€ HomePage.jsx
│   ā”œā”€ā”€ ProductsPage.jsx
│   └── ProfilePage.jsx
│
ā”œā”€ā”€ services/
│   ā”œā”€ā”€ authService.js
│   └── apiService.js
│
ā”œā”€ā”€ utils/
│   ā”œā”€ā”€ formatDate.js
│   └── validation.js
│
ā”œā”€ā”€ App.jsx
└── index.js

Good for:
āœ… Small to medium apps
āœ… Simple projects
āœ… Learning/prototypes

Challenges:
āŒ Hard to scale
āŒ Mixing unrelated code
āŒ Difficult to find related files

Pattern 3: Hybrid Structure (Best for Most Apps)

hybrid.txt
src/
ā”œā”€ā”€ features/            # Feature-specific code
│   ā”œā”€ā”€ auth/
│   │   ā”œā”€ā”€ LoginForm.jsx
│   │   ā”œā”€ā”€ useAuth.js
│   │   └── authService.js
│   │
│   └── products/
│       ā”œā”€ā”€ ProductList.jsx
│       ā”œā”€ā”€ ProductCard.jsx
│       └── useProducts.js
│
ā”œā”€ā”€ components/          # Shared components only
│   ā”œā”€ā”€ Button.jsx
│   ā”œā”€ā”€ Input.jsx
│   └── Modal.jsx
│
ā”œā”€ā”€ hooks/              # Shared hooks only
│   ā”œā”€ā”€ useDebounce.js
│   └── useLocalStorage.js
│
ā”œā”€ā”€ layouts/            # Page layouts
│   ā”œā”€ā”€ MainLayout.jsx
│   └── DashboardLayout.jsx
│
ā”œā”€ā”€ pages/              # Route components
│   ā”œā”€ā”€ HomePage.jsx
│   ā”œā”€ā”€ DashboardPage.jsx
│   └── NotFoundPage.jsx
│
ā”œā”€ā”€ services/           # API services
│   └── api.js
│
ā”œā”€ā”€ utils/              # Utilities
│   ā”œā”€ā”€ formatDate.js
│   └── constants.js
│
ā”œā”€ā”€ App.jsx
└── index.js

āœ… Best of both worlds
āœ… Clear separation
āœ… Easy to navigate
āœ… Scales well

Component File Organization

Single File Component

Button.jsx
// Simple components in one file
import React from 'react'
import './Button.css'

function Button({ children, variant = 'primary', onClick, disabled }) {
  return (
    <button 
      className={`btn btn-${variant}`}
      onClick={onClick}
      disabled={disabled}
    >
      {children}
    </button>
  )
}

export default Button

// Good for: Simple, self-contained components

Component with Folder

folder-structure.txt
ProductCard/
ā”œā”€ā”€ ProductCard.jsx       # Main component
ā”œā”€ā”€ ProductCard.module.css
ā”œā”€ā”€ ProductCard.test.jsx  # Tests
ā”œā”€ā”€ useProductCard.js     # Component-specific hook
└── index.js              # Public API

// index.js
export { default } from './ProductCard'
export { useProductCard } from './useProductCard'

Good for:
āœ… Complex components
āœ… Components with tests
āœ… Components with styles
āœ… Components with hooks

Feature Module Structure

feature-module.txt
auth/
ā”œā”€ā”€ components/
│   ā”œā”€ā”€ LoginForm/
│   │   ā”œā”€ā”€ LoginForm.jsx
│   │   ā”œā”€ā”€ LoginForm.module.css
│   │   └── LoginForm.test.jsx
│   │
│   └── SignupForm/
│       ā”œā”€ā”€ SignupForm.jsx
│       └── SignupForm.test.jsx
│
ā”œā”€ā”€ hooks/
│   ā”œā”€ā”€ useAuth.js
│   └── useLogin.js
│
ā”œā”€ā”€ services/
│   └── authService.js
│
ā”œā”€ā”€ utils/
│   └── validation.js
│
ā”œā”€ā”€ types.ts             # TypeScript types
ā”œā”€ā”€ constants.js         # Feature constants
└── index.js             # Public exports

// index.js - Export only what other features need
export { LoginForm, SignupForm } from './components'
export { useAuth } from './hooks'
export { login, logout } from './services/authService'

Component Categories

1. Page Components

page-component.jsx
// pages/DashboardPage.jsx
import DashboardLayout from '../layouts/DashboardLayout'
import { UserStats, RecentActivity, QuickActions } from '../features/dashboard'

function DashboardPage() {
  return (
    <DashboardLayout>
      <h1>Dashboard</h1>
      <UserStats />
      <RecentActivity />
      <QuickActions />
    </DashboardLayout>
  )
}

export default DashboardPage

// Characteristics:
// - Corresponds to routes
// - Composes other components
// - Minimal logic
// - Usually in pages/ folder

2. Layout Components

layout-component.jsx
// layouts/MainLayout.jsx
import Header from '../components/layout/Header'
import Footer from '../components/layout/Footer'
import Sidebar from '../components/layout/Sidebar'

function MainLayout({ children }) {
  return (
    <div className="main-layout">
      <Header />
      <div className="content-wrapper">
        <Sidebar />
        <main className="main-content">
          {children}
        </main>
      </div>
      <Footer />
    </div>
  )
}

export default MainLayout

// Characteristics:
// - Wraps other components
// - Defines page structure
// - Usually receives children
// - Shared across pages

3. Feature Components

feature-component.jsx
// features/products/ProductList.jsx
import { useProducts } from './hooks/useProducts'
import ProductCard from './ProductCard'
import LoadingSpinner from '../../components/LoadingSpinner'

function ProductList({ category }) {
  const { products, loading, error } = useProducts(category)
  
  if (loading) return <LoadingSpinner />
  if (error) return <div>Error: {error}</div>
  
  return (
    <div className="product-list">
      {products.map(product => (
        <ProductCard key={product.id} product={product} />
      ))}
    </div>
  )
}

export default ProductList

// Characteristics:
// - Feature-specific logic
// - May fetch data
// - Business logic
// - In features/ folder

4. UI/Shared Components

ui-component.jsx
// components/ui/Button.jsx
function Button({ 
  children, 
  variant = 'primary', 
  size = 'medium',
  onClick, 
  disabled 
}) {
  return (
    <button 
      className={`btn btn-${variant} btn-${size}`}
      onClick={onClick}
      disabled={disabled}
    >
      {children}
    </button>
  )
}

export default Button

// Characteristics:
// - Generic/reusable
// - No business logic
// - Presentation only
// - Used across features
// - In components/ folder

Import/Export Patterns

Named vs Default Exports

export-patterns.jsx
// āœ… Default export - Good for main component
// Button.jsx
function Button() { }
export default Button

// Usage
import Button from './Button'

// āœ… Named exports - Good for multiple exports
// utils.js
export function formatDate() { }
export function formatCurrency() { }

// Usage
import { formatDate, formatCurrency } from './utils'

// āœ… Hybrid - Component + utilities
// ProductCard.jsx
function ProductCard() { }
export default ProductCard

export function formatPrice() { }
export const CURRENCY = 'USD'

// Usage
import ProductCard, { formatPrice, CURRENCY } from './ProductCard'

// āŒ Avoid mixing patterns inconsistently
// Pick one pattern and stick to it!

Index Files (Barrel Exports)

barrel-exports.jsx
// components/ui/index.js
export { default as Button } from './Button'
export { default as Input } from './Input'
export { default as Modal } from './Modal'
export { default as Card } from './Card'

// Usage - Clean imports!
import { Button, Input, Modal } from '../components/ui'

// Instead of:
import Button from '../components/ui/Button'
import Input from '../components/ui/Input'
import Modal from '../components/ui/Modal'

// āš ļø Warning: Can affect tree-shaking
// Use with caution in large apps

// Better for features:
// features/auth/index.js
export { LoginForm } from './components/LoginForm'
export { SignupForm } from './components/SignupForm'
export { useAuth } from './hooks/useAuth'

// Now other features import from feature root:
import { LoginForm, useAuth } from '../features/auth'

Absolute Imports

absolute-imports.jsx
// jsconfig.json or tsconfig.json
{
  "compilerOptions": {
    "baseUrl": "src"
  }
}

// Before: Relative imports
import Button from '../../../components/ui/Button'
import { useAuth } from '../../../hooks/useAuth'

// After: Absolute imports
import Button from 'components/ui/Button'
import { useAuth } from 'hooks/useAuth'

// Or with path aliases:
{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@components/*": ["src/components/*"],
      "@hooks/*": ["src/hooks/*"],
      "@utils/*": ["src/utils/*"],
      "@features/*": ["src/features/*"]
    }
  }
}

// Usage:
import Button from '@components/ui/Button'
import { useAuth } from '@hooks/useAuth'

// Benefits:
// āœ… Easier refactoring
// āœ… More readable
// āœ… Less ../ navigation

Organization Best Practices

  1. Start Simple, Refactor Later
start-simple.txt
Small app (< 10 components):
src/
ā”œā”€ā”€ components/
ā”œā”€ā”€ App.jsx
└── index.js

Medium app (10-50 components):
src/
ā”œā”€ā”€ components/
ā”œā”€ā”€ hooks/
ā”œā”€ā”€ utils/
ā”œā”€ā”€ pages/
└── App.jsx

Large app (50+ components):
src/
ā”œā”€ā”€ features/
ā”œā”€ā”€ components/
ā”œā”€ā”€ hooks/
ā”œā”€ā”€ utils/
ā”œā”€ā”€ pages/
└── App.jsx

Don't over-engineer early!
  1. Co-locate Related Files
colocate.txt
āœ… Keep related files together
ProductCard/
ā”œā”€ā”€ ProductCard.jsx
ā”œā”€ā”€ ProductCard.css
ā”œā”€ā”€ ProductCard.test.jsx
└── useProductCard.js

āŒ Don't separate by type when closely related
components/
  └── ProductCard.jsx
styles/
  └── ProductCard.css
tests/
  └── ProductCard.test.jsx
hooks/
  └── useProductCard.js
  1. Use Consistent Naming

Pick a convention and stick to it:

  • Components: PascalCase
  • Files: Match component name
  • Folders: Match main file
  • Utilities: camelCase
  • Constants: UPPER_SNAKE_CASE
  1. One Component Per File
one-component.jsx
// āŒ Avoid: Multiple components in one file
function Header() { }
function Navigation() { }
function UserMenu() { }

// āœ… Good: One main component
function Header() { }

// Small helper components are OK
function HeaderLink({ href, children }) { }

// āœ… Better: Extract if used elsewhere
// Header.jsx
import Navigation from './Navigation'
import UserMenu from './UserMenu'

function Header() {
  return (
    <header>
      <Navigation />
      <UserMenu />
    </header>
  )
}
  1. Keep Component Files Small

If component exceeds 200-300 lines, consider:

  • Extracting sub-components
  • Moving logic to custom hooks
  • Creating utility functions
  • Splitting into multiple components
  1. Document Complex Structures
README.md
# Project Structure

## Folder Organization
- `/features` - Feature-based modules
- `/components` - Shared/reusable components
- `/hooks` - Custom React hooks
- `/utils` - Helper functions
- `/pages` - Page components

## Naming Conventions
- Components: PascalCase (e.g., `UserProfile.jsx`)
- Hooks: camelCase with "use" prefix (e.g., `useAuth.js`)
- Utils: camelCase (e.g., `formatDate.js`)

## Import Rules
- Use absolute imports with @ aliases
- Barrel exports in feature modules
- Default exports for components

Remember:

There's no "perfect" structure for all projects!

Choose based on:
• Team size and preferences
• Project complexity
• Domain requirements
• Future scalability needs

Consistency is more important than the specific pattern!

Key Takeaways

  • Components use PascalCase, utilities use camelCase
  • Feature-based structure scales better than type-based
  • Hybrid approach works for most applications
  • Co-locate related files (component + styles + tests)
  • Use barrel exports (index.js) for clean imports
  • Consider absolute imports with path aliases
  • One main component per file
  • Keep component files under 200-300 lines
  • Separate shared components from feature components
  • Start simple and refactor as you grow
  • Document your structure for the team
  • Consistency matters more than perfection
  • Choose structure based on team and project needs

What's Next?

You now understand how to organize React projects for maintainability and scalability! You know file naming conventions, folder structures, and best practices.

In the next lesson, you'll learn about Performance Optimization:

  • Using React.memo to prevent re-renders
  • Code splitting with lazy loading
  • Optimizing bundle size
  • Profiling React applications
  • Common performance patterns

Get ready to make your React apps blazing fast! ⚔

Learning best practices for organizing React components and project structure!

Previous
Dynamic Routes and Parameters
Next
Performance Optimization

Never Miss a New React Tutorial

Join 2,000+ developers learning React step-by-step. Get new tutorials, tips, and exclusive resources delivered to your inbox - completely FREE.

You might also like

UI Components

Ready-made components for your projects

Developer Tools

Boost productivity with handy generators

HTML Game

Learn HTML concepts through interactive gameplay

Join Our Web Development Training Program

Master frontend & backend development with hands-on projects.

React Tutorials

0 of 42 completed

Your Progress0%

Topics

Getting Started

  • What is React?
  • React vs Vanilla JavaScript
  • Setting Up Your Environment
  • Your First React App

JSX Fundamentals

  • Introduction to JSX
  • JSX Expressions and Variables
  • Conditional Rendering
  • Lists and Keys
  • Styling in JSX

Components Basics

  • Function Components
  • Props
  • Children Prop
  • Props Destructuring
  • Component Composition

State Management

  • Introduction to State
  • useState Hook
  • State Updates and Re-renders
  • Multiple State Variables
  • State Best Practices

Events and Interactivity

  • Handling Events
  • Event Objects
  • Forms in React
  • Form Validation

Side Effects and Data

  • Introduction to useEffect
  • Data Fetching
  • Cleanup Functions
  • Dependency Arrays

Advanced Hooks

  • useRef Hook
  • useContext Hook
  • useMemo Hook
  • useCallback Hook

React Patterns

  • Custom Hooks
  • Higher-Order Components
  • Render Props Pattern

React Router

  • Introduction to React Router
  • Routes and Navigation
  • Dynamic Routes and Parameters

Best Practices

  • Component Organization
  • Performance Optimization
  • Error Handling
  • Testing React Components

Real World Project

  • Building a Complete App
Falytom logoFALYTOM

Learn technologies like HTML, CSS, JavaScript, React, NodeJS and more through interactive games, tutorials, components and free tools. Transform your businesses with AI chatbots, SEO-optimized websites, and professional development services.

Ā© 2025 Tomilola Group
  • Facebook logo
  • Twitter logo
  • Instagram logo
  • LinkedIn logo
  • GitHub logo
  • YouTube logo