Code Monkey home page Code Monkey logo

react-structure's Introduction

react-structure

React.js × Next.js でのディレクトリ構造検討

ディレクトリ構造

├── components
│   ├── elements
│   ├── parts
│   ├── forms
│   ├── frames
│   └── templates
├── features
│   └── users
│       ├── EditUser
│       │   ├── EditUserContainer.tsx
│       │   ├── EditUserPresentation.tsx
│       │   └── index.ts
│       ├── DetailUser
│       ├── Users
│       ├── Components
│       └── type.ts
├── layouts
├── pages
└── styles

components

再利用可能なコンポーネントの一覧となるディレクトリ。

parts・・・UI を構成する最小部品コンポーネント。最も再利用性が高い。(atomic design で言うと atoms) templates・・・parts または template を組み合わせたコンポーネント。(atomic design で言うと molecules)

各コンポーネント内でテストや Storybook などを用いてコンポーネントの品質を担保する責務を持つ。

features

各機能別にコンポーネント、ロジック、型などを管理するディレクトリ。 理想としては機能がドロップしたときにディレクトリを削除するだけで完結することが望ましい。

├── features
│   └── users
│       ├── EditUser
│       │   ├── EditUserContainer.tsx
│       │   ├── EditUserPresentation.tsx
│       │   └── index.ts
│       ├── DetailUser
│       ├── Users
│       ├── Components
│       └── type.t

第一階層

features ディレクトリ直下には機能名称となるディレクトリを作成する。 だいたいのケースでは URL の 2 階層目に来る名称がこれに当たることが多い。

ex) users, clients, authentication など

第二階層

第二階層は細かく機能別にディレクトリを作成する。基本的には Page から呼ばれるコンポーネントが並ぶことになるため、画面構成と同じものが作られる。

│       ├── EditUser
│       ├── DetailUser
│       ├── Users
│       ├── Components
│       └── type.t

またその他にも機能間で共通の型や機能内でのみ共有するコンポーネントなども管理する。

第三階層

各機能は基本的にコンテナ・プレゼンテーションパターンを導入する。 https://zenn.dev/morinokami/books/learning-patterns-1/viewer/presentational-container-pattern

├── features
│   └── users
│       ├── EditUser
│       │   ├── EditUserContainer.tsx
│       │   ├── EditUserPresentation.tsx
│       │   └── index.ts

API 通信を伴うものやデータの扱いはコンテナで行い、画面の構成やフォームのバリデーションなどの処理はプレゼンテーション側で責務を持つ。

react-structure's People

Contributors

ikekiyo avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.