Skip to main content

Component structure

Good React components start small, do one clear job, and become reusable because their purpose is easy to understand. Structure matters because the quality of your components shapes the quality of the whole application. Beginners often create large components too early. A better approach is to start with the smallest useful version, then extract pieces when you see repetition or mixed responsibilities.

Useful questions for component structure are:

  • What is this component responsible for?
  • Which data does it need?
  • Which parts are stable enough to be reused?
  • Is this component representing a domain idea or only a visual wrapper?

A healthy component usually has a clear public API through props. That makes it easier to reuse in different screens without duplicating behavior.

Atomic Design helps here by giving you language for size and responsibility:

  • atoms are basic UI elements
  • molecules combine a few related atoms
  • organisms assemble larger sections of a page

DDD adds another filter: the name and intent of the component should still make sense in the business domain. A CustomerSummary tells a better story than a vague InfoBox.

How do components operate?

Components are functions that return JSX. They can receive data through props and manage their own state with hooks. The component's return value describes what should be rendered on the screen. When a component is used in JSX, it creates an instance of that component. React then calls the component function to determine what to render. If the component has state or effects, React manages those as well.

Based upon the "Single Way Data Flow"-principle, data flows down from parent components to child components through props. When a component's state changes, React re-renders that component and its children to reflect the new state.