Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
SOLIDから考える良いコンポーネントの設計原則
Search
Tetsuya Negishi
October 29, 2021
Technology
1.6k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
SOLIDから考える良いコンポーネントの設計原則
Tetsuya Negishi
October 29, 2021
More Decks by Tetsuya Negishi
See All by Tetsuya Negishi
React Hooksで美しいコードを書く / Writing beautiful code using React Hooks
tetsuyanegishi
0
210
TypeScriptの型定義が JavaScriptのバグを駆逐する
tetsuyanegishi
3
970
React初学者が知らない コンポーネント分割テクニック
tetsuyanegishi
1
520
AWS Amplifyで作るサーバーレスバックエンド
tetsuyanegishi
3
2.1k
リアルタイムデータベース Cloud Firestore入門
tetsuyanegishi
10
9k
ブロックチェーンのマイニングとはなにか
tetsuyanegishi
1
110
スクラム開発の手法と実例
tetsuyanegishi
0
280
Other Decks in Technology
See All in Technology
JAWS-UGグッズ職人仕事の流儀
kentapapa
0
120
How to Design Configuration for Rails Applications
willnet
1
850
Code for Security プロジェクト紹介 2026年10月
yu23ki14
0
110
sue445's proposals 2026
sue445
0
110
Gemini Intelligence 入門 ― AppFunctions と Gemini Nano
takuroabe
0
300
1つのリクエストを追って理解する - llm-dのP/D分離
akhino
1
170
スプシの手作業からの解脱 ~更新はClaude Codeに、見せ方と使い方はGASアプリに任せる~
kentarofujii
0
160
M5Stackで作る BLEマウス GPSログの世界
tomokusaba
PRO
0
440
『SAR衛星データ解析入門』のご紹介とその応用
syuchimu
0
120
Refining Active Record
shugo
0
170
パスキーの自動テストはどこまでいけるのか
teamlab
PRO
0
290
PagerDuty Tech Hub-鳴らすけれど、人は動かない
ezaki
0
180
Featured
See All Featured
New Earth Scene 8
popppiees
4
2.7k
Site-Speed That Sticks
csswizardry
13
1.6k
From π to Pie charts
rasagy
1
400
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
480
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
550
Building Flexible Design Systems
yeseniaperezcruz
330
41k
Documentation Writing (for coders)
carmenintech
77
5.6k
Building a Scalable Design System with Sketch
lauravandoore
464
34k
Amusing Abliteration
ianozsvald
1
350
The browser strikes back
jonoalderson
0
1.8k
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.9k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
Transcript
© commmune Inc. All rights reserved SOLIDから考える 良いコンポーネントの設計原則 1 #ReactLT
© commmune Inc. All rights reserved 2 自己紹介 • 根岸徹也
• コミューン株式会社 副業:2018/11 ~ 2020/11 正社員:2020/12 ~ • フロントエンド + サーバサイド #ReactLT
© commmune Inc. All rights reserved 3 SOLIDとは #ReactLT
© commmune Inc. All rights reserved 4 SOLIDとは • 変更に強い・理解しやすい・
再利用しやすいコードを作るための設計原則 • オブジェクト指向を想定して提唱されたもの ◦ 考え方のコアの部分は普遍的なもの ◦ Reactのコンポーネントを作るときにも適用できる #ReactLT
© commmune Inc. All rights reserved 5 5つの原則 S:単一責任の原則 (SRP)
O:オープン・クローズドの原則 (OCP) L:リスコフの置換原則 (LSP) I:インターフェイス分離の原則 (ISP) D:依存関係逆転の原則 (DIP) #ReactLT
© commmune Inc. All rights reserved 6 5つの原則 S:単一責任の原則 (SRP)
O:オープン・クローズドの原則 (OCP) L:リスコフの置換原則 (LSP) I:インターフェイス分離の原則 (ISP) D:依存関係逆転の原則 (DIP) #ReactLT
© commmune Inc. All rights reserved 7 単一責任の原則 #ReactLT
© commmune Inc. All rights reserved 8 単一責任の原則 「モジュールを変更する理由はたった1つであるべきである」 #ReactLT
© commmune Inc. All rights reserved 9 単一責任の原則 「モジュールを変更する理由はたった1つであるべきである」 =>
役割を意識してコンポーネントを分ける とコンポーネントの変更理由が1つになりやすい #ReactLT
© commmune Inc. All rights reserved 10 単一責任の原則(ケーススタディ) #ReactLT
© commmune Inc. All rights reserved 11 単一責任の原則(ケーススタディ) • 円形画像のアイコン
-> <CircleImage /> • ユーザ名がボールド体 -> <Text bold /> • ユーザIDがグレーの文字 -> <Text color=“gray” /> • 左に画像アイコン, 右にユーザ情報 を表示 -> <MediaObjectLayout /> #ReactLT
© commmune Inc. All rights reserved 12 単一責任の原則(ケーススタディ) #ReactLT
© commmune Inc. All rights reserved 13 オープン・クローズドの 原則 #ReactLT
© commmune Inc. All rights reserved 14 オープン・クローズドの原則 「既存のコードを変更せず、新たにコードを追加するだけで振る舞い を変更できるようにするべき」
#ReactLT
© commmune Inc. All rights reserved 15 オープン・クローズドの原則 「既存のコードを変更せず、新たにコードを追加するだけで振る舞い を変更できるようにするべき」
=> propsで受け取る値の型をReact.ReactNode にすると既存コードを変更せずに振る舞いを 変更しやすい #ReactLT
© commmune Inc. All rights reserved 16 オープン・クローズドの原則(ケーススタディ) モーダルコンポーネントのpropsを考える #ReactLT
© commmune Inc. All rights reserved 17 オープン・クローズドの原則(ケーススタディ) #ReactLT
© commmune Inc. All rights reserved 18 オープン・クローズドの原則(ケーススタディ) タイトルの先頭にアイコンを入れたい 右下にボタンを入
れたい #ReactLT
© commmune Inc. All rights reserved 19 オープン・クローズドの原則(ケーススタディ) タイトルの先頭にアイコンを入れたい 右下にボタンを入
れたい React.ReactNodeにすると string, numberに加えて `<div>エレメント</div>` を受け取れるようになる #ReactLT
© commmune Inc. All rights reserved 20 オープン・クローズドの原則(ケーススタディ) propsの型を `React.ReactNode`
にするだけで拡張性が 段違いに上がる #ReactLT
© commmune Inc. All rights reserved 21 まとめ • SOLIDとは変更に強く、理解しやすく、再利用しやすいコードを
作るための設計原則 • 単一責任の原則を守るために 役割を意識してコンポーネントを分ける • オープン・クローズドの原則を守るために React.ReactNode型をpropsに活用すべき #ReactLT
© commmune Inc. All rights reserved 22 参考 • Atomic
Design ~堅牢で使いやすいUIを効率良く設計する [技術評論社 (2018/4/25)] ◦ コンポーネント分割のテクニックを学びたい人にオススメ • Clean Architecture 達人に学ぶソフトウェアの構造と設計 [ドワンゴ (2018/8/1)] ◦ SOLIDについて知りたい人向け • 良いコードとは何か - エンジニア新卒研修 スライド公開 (https://note.com/cyberz_cto/n/n26f535d6c575) ◦ SOLIDを守るとなぜ良いコードになるのか背景がよく分かる #ReactLT