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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
サーバーレスをどこまで使う? WebRTC対戦ゲームで選んだVPSとの共存設計
kaidouji85
0
450
ScotSecure West 2026 - Glasgow
raybugg
0
180
Making AI Agents Safe and Fast- Jev, Obsidian, and the Meta-Harness
x5gtrn
PRO
0
140
顧客に向き合う開発組織へ。リアーキテクチャとフィーチャーチーム化で挑む組織改革
safie
0
2.5k
作って終わりじゃないサーバーレス 〜9年運用する大規模EC物流API基盤の設計・運用のリアル〜
zozotech
PRO
0
540
DORA_Metrics.pdf
wagnerfusca
1
110
Antigravity SDK for the Java Developer
glaforge
0
210
Oracle Cloud Infrastructure(OCI):Onboarding Session(はじめてのOCI/Oracle Supportご利⽤ガイド)
oracle4engineer
PRO
2
21k
AIエージェントの一手は 誰も見ていない - Falco拡張OSS「Prempti」とeBPFで サーバーレス実行基盤を二層防御する
keitah
1
590
Vibe Coding で作ったプロダクトをどう安全に動かすか / How to Safely Run Products Built with Vibe Coding
glidenote
0
720
なぜ「決定性」が 決定的に重要なのか? Durable Execution 基盤の数理的理解 #serverlessjp / ServerlessDays Tokyo 2026
ytaka23
4
1.3k
人にやさしく、AIにやさしく、書き手を選ばないIaCのガードレール再考 / Rethinking IaC Guardrails for Humans and AI Alike
kohbis
5
1.2k
Featured
See All Featured
Designing for Timeless Needs
cassininazir
1
510
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
290
Side Projects
sachag
456
43k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
420
Making the Leap to Tech Lead
cromwellryan
135
10k
Visualization
eitanlees
153
17k
Bash Introduction
62gerente
615
220k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
1k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
The Language of Interfaces
destraynor
162
27k
Fireside Chat
paigeccino
43
4k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
840
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