Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
これからの React の非同期処理について考える
Search
kotaro takahashi
December 19, 2019
Programming
1
740
これからの React の非同期処理について考える
スタートアップ×React LT大会 Coral Developers Nightにて、10分間のLTで登壇。
Reactと非同期処理から連想出来るトピックについて早口オタク喋りした。
kotaro takahashi
December 19, 2019
Tweet
Share
More Decks by kotaro takahashi
See All by kotaro takahashi
もしもエンジニアが Inspiredを読んだら ~PdMを兼任した半年間の奮闘記~
k4h4shi
0
76
Other Decks in Programming
See All in Programming
DroidKnights 2025 - 다양한 스크롤 뷰에서의 영상 재생
gaeun5744
3
300
今ならAmazon ECSのサービス間通信をどう選ぶか / Selection of ECS Interservice Communication 2025
tkikuc
12
2.9k
エラーって何種類あるの?
kajitack
5
280
関数型まつりレポート for JuliaTokai #22
antimon2
0
130
SODA - FACT BOOK
sodainc
1
1.1k
Using AI Tools Around Software Development
inouehi
0
1.2k
F#で自在につくる静的ブログサイト - 関数型まつり2025
pizzacat83
0
310
AIエージェントはこう育てる - GitHub Copilot Agentとチームの共進化サイクル
koboriakira
0
220
XSLTで作るBrainfuck処理系
makki_d
0
210
Team topologies and the microservice architecture: a synergistic relationship
cer
PRO
0
950
来たるべき 8.0 に備えて React 19 新機能と React Router 固有機能の取捨選択とすり合わせを考える
oukayuka
2
830
GraphRAGの仕組みまるわかり
tosuri13
7
460
Featured
See All Featured
Fantastic passwords and where to find them - at NoRuKo
philnash
51
3.3k
Designing Experiences People Love
moore
142
24k
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Building a Modern Day E-commerce SEO Strategy
aleyda
41
7.3k
BBQ
matthewcrist
89
9.7k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
48
5.4k
For a Future-Friendly Web
brad_frost
179
9.8k
Automating Front-end Workflow
addyosmani
1370
200k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
The Language of Interfaces
destraynor
158
25k
YesSQL, Process and Tooling at Scale
rocio
173
14k
Transcript
これからの React の非同期処理について考える スタートアップ×React LT 大会 Coral Developers Night
kotaro.t ID: @k4h4shi 所属: 株式会社Handii ロール: フロントエンドエンジニ ア
はじめに
非同期処理はどこに書く?
非同期処理関数() { 非同期処理の開始アクションの発行; try { 非同期処理の呼び出し; 非同期処理の完了アクションの発行; } catch (e) {
非同期処理の失敗アクションの発行; } }
redux-saga
function* asyncTask() { yield put(asyncActions.start()); try { const result = yeild call(asyncFunction); yield put(asyncActions.done(result)); } catch (e) { yield put(asyncActions.failed(e)) } }
Saga の良い点
モック要らずで手続きのテストが容易 コンポーネントとタスクが疎に出来る API が豊富(delay, retry, cancel, throttle, debounce)
Saga の悪い点
TS の型推論があんま効かない 見慣れないジェネレータ記法でロックインされる 影響と副作用を一手に引き受けるのでカオスになりやすい
Saga は便利だが、扱いが難しい道具
None
そんな時...
React 16.8 で React Hooks がリリースされた
もう Hooks でいいのでは...?
Hooks での非同期処理について考えた
const useDoAsyncOperation = () => { const dispatch = useDispatch(); const doAsyncOperation = async () => { dispatch(asyncActions.start()); try { const result = await asyncFunction(); dispatch(asyncActions.done(result)); } catch (e) { dispatch(asyncActions.failed(e)) }
} return doAsyncOperation; }
const component = () => { const doAsyncOperations = useDoAsyncOperation(); return ( <button onClick={doAsyncOperations}>do asyncOperation</button> ) }
None
これまでと今のReact の非同期処理について考えた...
これからの React の非同期処理について考える
Suspense for Data Fetching (Experimental)
const ProfilePage = React.lazy(() => import('./ProfilePage')); // Lazy-loaded // Show a spinner while the profile is loading <Suspense fallback={<Spinner />}> <ProfilePage /> </Suspense>
const resource = fetchProfileData(); function ProfilePage() { return ( <Suspense fallback={<h1>Loading profile...</h1>}> <ProfileDetails /> <Suspense fallback={<h1>Loading posts...</h1>}> <ProfileTimeline /> </Suspense> </Suspense>
); } function ProfileDetails() { const user = resource.user.read(); return <h1>{user.name}</h1>; } function ProfileTimeline() { const posts = resource.posts.read(); return ( <ul> {posts.map(post => ( <li key={post.id}>{post.text}</li> ))}
None
宣言的に記述する事でReact による最適化の恩恵が受けら れる
さいごに
ご清聴ありがとうございました