SlideShare a Scribd company logo
1 of 13
Download to read offline
React/Reduxに
Selectorを導⼊したら
幸せになった話
MixLeap Study #59
ヤフー株式会社 松井 真⼦
⾃⼰紹介
【名前】
松井 真⼦(まつい まこ)
【業務】
ヤフーに 2018年新卒⼊社
ショッピングの⼊稿ツール開発(React/Redux)
↓
PayPayモール Androidアプリ開発(Kotlin)
【趣味】
釣り、あつまれどうぶつの森 @makomsh
⾃⼰紹介
【名前】
松井 真⼦(まつい まこ)
【業務】
ヤフーに 2018年新卒⼊社
ショッピングの⼊稿ツール開発(React/Redux)
↓
PayPayモール Androidアプリ開発(Kotlin)
【趣味】
釣り、あつまれどうぶつの森 @makomsh
このお話します
⼊稿ツールの簡単なイメージ
簡単にいうとWordPressみたいなもの
⼊⼒データをもとにHTMLを⾃動で⽣成するシステムの⼊⼒部分
⼊稿データ
〇〇モジュールの⼊⼒フォーム
…
⼊稿ツール
⽣成されたページ
https://shopping.yahoo.co.jp/promotion/coupon/zorome/
具体例 ‒画像モジュール‒
⼊稿ツール ユーザがアクセスしたWeb画⾯
画像モジュール
altタグ
画像URL
クーポン争奪戦
https://hogehoge
引⽤ : https://shopping.yahoo.co.jp/promotion/coupon/zorome/
⽣成されたHTML
<img src="https://hogehoge" alt="ゾロ⽬の⽇クーポン争奪戦">
⼊稿ツールを開発する時に困ったこと
• コンポーネント間の依存関係が複雑になってしまった
• バリデーションの実装が複雑に
• データ構造が複雑&ネストが深い
→ 各フォーム、モジュールのバリデーション結果も保持が原因の1つ
⼊稿ツールを開発する時に困ったこと
• コンポーネント間の依存関係が複雑になってしまった
→ Atomic Designを導⼊して作り直し
• バリデーションの実装が複雑に
• データ構造が複雑&ネストが深い
→ 各フォーム、モジュールのバリデーション結果も保持が原因の1つ
バリデーションのタイミングが難しい
propsが変更されるタイミングでバリデーションをする
• フォームに⼊⼒される時
• DBに保存されているデータをAPIで取得した時
ActionやReducerの中ではロジックを持たせたくない
→ライフサイクルメソッド( ComponentDidUpdate )の中で実装
個々のモジュールで全て実装しないといけない
そもそもバリデーションが多すぎる
• ⼊⼒フォーム単体
• モジュール単体(複数の⼊⼒フォームを統括)
• ページ全体として(全モジュールを統括)
→ ビジネス要件が絡んでくるところでより複雑になり、
バリデーションなのでしっかりテストしたいが、⼤変。
そんな時に助けてくれたのが
selector
(reduxjs/reselect)
https://github.com/reduxjs/reselect
Reselectを使うと?
Stateが渡された時に、関⼼のある値を返すことができる
= バリデーションを切り出して、結果をpropsとして渡せる
→ バリデーション結果を保持しなくて良い
Before / After
• コードがスッキリ!
• テストが書きやすい!
責務分けができたことで
品質が担保される
Before
After
まとめ
• Selectorの機能を使うと、余計なデータを保持しなくて良い
• バリデーションを切り分けることができたので、
コードもスッキリし、テストもしやすくなった
注意
他のライブラリを⽤いた実装での制約によりreselectを使いましたが、
Hooks APIの標準機能で同様のことができるようになっていそう
(公式でもUseSelectorとreselectを同時に使う例もあるので⽤途に合わせて使い分けを)

More Related Content

Recently uploaded

Recently uploaded (7)

NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
 
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)
 
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアルLoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
 
新人研修 後半 2024/04/26の勉強会で発表されたものです。
新人研修 後半        2024/04/26の勉強会で発表されたものです。新人研修 後半        2024/04/26の勉強会で発表されたものです。
新人研修 後半 2024/04/26の勉強会で発表されたものです。
 
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
 
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
 
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
LoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイスLoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイス
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
 

Featured

Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Saba Software
 
Introduction to C Programming Language
Introduction to C Programming LanguageIntroduction to C Programming Language
Introduction to C Programming Language
Simplilearn
 

Featured (20)

How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
 
Introduction to C Programming Language
Introduction to C Programming LanguageIntroduction to C Programming Language
Introduction to C Programming Language
 

MixLeap