Course contentsShow
← React
Lesson 1162 of 2,39630. Composition: Inversion of ControlFree lesson

Configuration Objects for Complex Behavior

Passing structured configuration to customize multiple related behaviors without excessive props.

Configuration Objects for Complex Behavior

What you'll learn: How to use structured configuration objects to customize multiple related behaviors without cluttering your component API with dozens of individual props.

The Problem with Many Behavior Props

When a component supports many customization options, you could pass each as a separate prop (enableFeatureA, featureBDelay, featureCCallback). But this quickly becomes unwieldy — imagine a table component with sorting, filtering, pagination, and selection options. That's potentially 15+ props!

The Configuration Object Pattern

Instead of spreading behavior customization across many props, group related settings into a single structured object:

// ❌ Too many props
<Table
  enableSort
  sortDirection="asc"
  sortBy="name"
  enableFilter
  filterDebounce={300}
  enablePagination
  pageSize={10}
  currentPage={1}
/>

// ✅ Configuration object
<Table
  config={{
    sort: { enabled: true, direction: "asc", by: "name" },
    filter: { enabled: true, debounce: 300 },
    pagination: { enabled: true, pageSize: 10, currentPage: 1 }
  }}
/>

When This Pattern Shines

This pattern gives users fine-grained control over complex, interconnected behaviors while keeping your component interface clean. The configuration object becomes a self-documenting blueprint of available customizations.

Think of it like a settings panel: instead of scattered checkboxes everywhere, you open one panel that organizes related options into sections.

It works especially well when:

  • You have 5+ related behavior toggles
  • Options naturally group into categories
  • Some options only make sense when others are enabled
  • You want partial customization with sensible defaults

Key Takeaway: Configuration objects consolidate multiple related behavior props into a single structured parameter, trading a flat prop list for organized, hierarchical control over complex features.