Knowledgebase

Structuring a React Application Print

  • frontenddevelopment, frontend, guide, howto, solution, zillionkinghost, hosting, support
  • 0

Organisation at scale.

WHAT TO ORGANISE BY

Feature, rather than by file type.

WHY

Files that change together should sit together. Grouping all components in one folder and all hooks in another separates them.

WHAT A FEATURE FOLDER CONTAINS

Its components Its hooks Its data access Its types

WHAT TO KEEP SHARED

Genuinely reusable components Utilities used across features Design system elements

WHAT TO SEPARATE

Presentational components from data fetching Business logic from components

WHY

Logic inside components cannot be tested or reused independently.

WHAT TO PUT LOGIC IN

Custom hooks, for stateful logic Plain functions, for everything else

WHAT TO AVOID

Very large components Components fetching data and also rendering complex interfaces Deeply nested folder structures

WHAT TO ESTABLISH EARLY

Conventions for naming, structure and where things belong.

WHY

They are difficult to introduce later.

WHAT TO DOCUMENT

Those conventions.


Was this answer helpful?
Back

Are you happy with your experience? Leave us a review on Trustpilot.


Trustpilot