ディレクトリ構成
よく使う主な構成です。
src/
├── components/ ベースとなる汎用UIを管理する場所
│ ├── Button/
│ │ ├── index.tsx
│ │ └── ...
│ ├── Input/
│ │ ├── index.tsx
│ │ └── ...
│ ├── index.ts
│ └── ...
├── features/ 機能ごとの関数を管理する場所
│ ├── auth/
│ │ ├── components/
│ │ │ └── ...
│ │ ├── hooks/
│ │ │ └── ...
│ │ ├── utils/
│ │ │ └── ...
│ │ └── index.ts
│ └── ...
├── hooks/ ReactのHooksを管理する場所
│ ├── useFetch.ts
│ ├── useInput.ts
│ └── ...
├── pages/ URLに沿ったページをまとめる場所
│ ├── home/
│ │ ├── index.tsx
│ │ └── ...
│ ├── about/
│ │ ├── index.tsx
│ │ └── ...
│ └── ...
├── styles/ tailwind-variantsなどでまとめたStyleを管理する場所
│ ├── Button.ts
│ ├── Input.ts
│ ├── index.ts
│ └── ...
├── themes/ テーマに関連したStyleを管理する場所
│ ├── tailwind.css
│ ├── blog.css
│ ├── tokens.css
│ └── ...
└── utils/ 汎用的なロジックを管理する場所
├── helpers.js
├── api.js
├── index.ts
└── ...
共通ルール
- 推奨していること
components
、features
、hooks
、utils
以下で作成されたものはimport先をまとめるためにindex.ts
を作成する。- UIとして使用するものは大文字の関数,ディレクトリ名にする
- ロジック、ページとして使用するものは小文字の関数,ディレクトリ名にする
- 関連するファイルは別にディレクトリを作成して同じディレクトリで管理する(例:.story.tsx,.test.tsxなど)
components配下のルール
- 推奨していること
src
直下のcomponents
、hooks
、utils
をimportして利用する
- 禁止していること
src
直下のfeatures
以下のものをimportして利用するsrc
直下のpages
以下のものをimportして利用する
features配下のルール
- 推奨していること
src
直下のcomponents
、features
、hooks
、utils
をimportして利用する
- 禁止していること
pages
以下のものをimportして利用する
pages配下のルール
- 推奨していること
src
直下のcomponents
、features
、hooks
、utils
をimportして利用する- URLに相当するものはディレクトリを作成して配下に
index.tsx
を作成する
- 禁止していること
src
直下のcomponents
、features
、hooks
、utils
に相当する関数をimportせずに直接実装するindex.tsx
以外のファイルを作成する