SlideShare a Scribd company logo
1 of 35
Download to read offline
こんな事が出来る様に
なった最近のReact
~ver 18.2以降で利用ができるこんなHookあんな
Hook~
株式会社タイミー 西浦太基
本LTで紹介する内容
・直近(v18.2~)で追加されたAPI、今回はHookに焦点 を当て、
いくつか凡例付きで紹介
・ざっくり最近のReactってこんな事が出来る様になったよ、と
いうイメージでカジュアルに紹介していきます。
西浦太基
・33歳(ギリギリ平成生まれ )
・2022/8 タイミーjoin
・前職はSES企業でWebエンジニアリングを9年
経験
・北海道札幌市在住
・妻と娘と3人ぐらし
・マリオRPG switchリメイクが楽しみ
(今日(20231117)発売日)
Hook is 何を簡単に紹介
ReactにおけるHookとは
・React 16.8で導入された機能で、クラスコンポーネントなしで状態管理やライフサイクルフックを
使用出来る様にするインターフェース。
・状態を扱うロジックの再利用を容易にし、コンポーネント間の状態の共有をシンプルにしたりす
る。
・サードパーティ製のHookや、独自にカスタムHookを作成することも可能
sample : useState
代表的なHook
・useState
⇨状態を持つ変数を関数コンポーネントで扱うHook
⇨Vueのdataプロパティに似ており、状態を宣言し、それを更新するための
関数を提供。
代表的なHook
・useEffect
⇨副作用(データフェッチング、購読、手動でのDOMの変更など)を行う為の
フック
⇨Vueで言うwatchとmounted、updatedライフサイクルフックに相当。
useSyncExternalStore
useSyncExternalStore
概要
・外部データソースとReactコンポーネント内で扱う状態を同期させる
フック
・useSyncExternalStore登場以前は、useEffectを用いて手続き的に
同期処理を記述する必要があった。
useSyncExternalStore
利用例
・ウィンドウサイズの追跡
useSyncExternalStore
利用例
・ウィンドウサイズの追跡
useSyncExternalStore
利用例 : 旧来の実装
・ウィンドウサイズの追跡
useOptimistic
useOptimistic
概要
・非同期アクションが進行中にも、最適な状態を表示するために利用す
るフック。
・非同期処理の完了を待たずに、最適なUI状態を提示することができ
る。
useOptimistic
利用例
・コメントの即時追加機能
useOptimistic
利用例 : 旧来の実装
・コメントの即時追加機能
useDeferredValue
useDeferredValue
概要
・遅延させたい値を引数として受け取り、その遅延された値を返すフッ
ク
・重いレンダリング処理が、他のユーザーインタラクションをブロッ
クしないように機能実装できる。
useDeferredValue
利用例
・リアルタイムチャートの更新
useDeferredValue
利用例 : 旧来の実装
・リアルタイムチャートの更新
ちなみに
Server ComponentにおけるHookの
扱いに関して
Server Component
is 何を簡単に
Server Component
・サーバー側でレンダリングされ、データ取得やその他のサーバーサイ ドロ
ジックを処理するためのコンポーネント。クライアント側の JavaScriptバン
ドルサイズを減らすことにより、パフォーマンスを向上させたり、サーバー側で
しか利用できないmoduleを使えたりという点が利点
・対して、従来のクライアントサイドで
処理を行うコンポーネントは読んで字の
如くクライアントコンポーネントと呼ば
れます
Server Component
・サーバーサイドでのみ、レンダリングするという点で、(Vue, Reactの)SSRと
は異なっている
Server ComponentではHookを使え
ないです
Server ComponentではHookを使えない
・Hookは基本的に状態を扱うために用いますが、サーバーサイドでは状態を
永続化する必要はほとんどない。
・状態管理や副作用(ライフサイクルイベント)はクライアント側の処理とし
て、責務を分ける設計が為されているため。
Next.js 13へのアップグレードを控えているタイ
ミーではどうしているか
Hook、Server Components両方で利用出来る
再利用性が高いコードを書く様に心がけてい
る
例 : ユーザー取得
例 : ユーザー取得
Server Component
Client Component(Custom Hook)
例 : ユーザー取得
Server Component
Client Component(Custom Hook)
userApi.ts
・ユーザー取得処理を抽
象化し、具体な処理を閉
じ込めてserver, clientい
ずれにも適応出来る様
に実装する
まとめ / 感想
・直近のアップデートにおいては真新しい挙動や進化は多くない印
象
・旧来の実装を、よりシンプル / イージーに行える様に最適
化する意図のAPIが多かった。
・Server Componentへのリプレイスも考慮し、カスタム
Hookを作成する場合も再利用性が高いコードを意識的に設計して
実装することが大事
ご清聴ありがとう
ございました!

More Related Content

Featured

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 2024Albert Qian
 
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 InsightsKurio // The Social Media Age(ncy)
 
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 2024Search Engine Journal
 
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 summarySpeakerHub
 
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 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 Tessa Mero
 
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 IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
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 managementMindGenius
 
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...RachelPearson36
 
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...Applitools
 
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 WorkGetSmarter
 
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...DevGAMM Conference
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationErica Santiago
 
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 wellSaba Software
 
Introduction to C Programming Language
Introduction to C Programming LanguageIntroduction to C Programming Language
Introduction to C Programming LanguageSimplilearn
 

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
 

React18.2以降で追加されたHooksについて