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
79
Other Decks in Programming
See All in Programming
One Enishi After Another
snoozer05
PRO
0
100
Web フロントエンドエンジニアに開かれる AI Agent プロダクト開発 - Vercel AI SDK を観察して AI Agent と仲良くなろう! #FEC余熱NIGHT
izumin5210
3
550
CSC305 Lecture 04
javiergs
PRO
0
270
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
180
『毎日の移動』を支えるGoバックエンド内製開発
yutautsugi
2
250
Goで実践するドメイン駆動開発 AIと歩み始めた新規プロダクト開発の現在地
imkaoru
4
850
bootcamp2025_バックエンド研修_WebAPIサーバ作成.pdf
geniee_inc
0
110
私達はmodernize packageに夢を見るか feat. go/analysis, go/ast / Go Conference 2025
kaorumuta
2
570
Introducing ReActionView: A new ActionView-Compatible ERB Engine @ Kaigi on Rails 2025, Tokyo, Japan
marcoroth
3
1k
Software Architecture
hschwentner
6
2.3k
Devoxx BE - Local Development in the AI Era
kdubois
0
130
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
410
Featured
See All Featured
Java REST API Framework Comparison - PWX 2021
mraible
34
8.9k
Speed Design
sergeychernyshev
32
1.2k
Side Projects
sachag
455
43k
RailsConf 2023
tenderlove
30
1.2k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
1.7k
Optimising Largest Contentful Paint
csswizardry
37
3.5k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
53k
Code Review Best Practice
trishagee
72
19k
GraphQLの誤解/rethinking-graphql
sonatard
73
11k
The Straight Up "How To Draw Better" Workshop
denniskardys
238
140k
Building a Modern Day E-commerce SEO Strategy
aleyda
44
7.8k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
620
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 による最適化の恩恵が受けら れる
さいごに
ご清聴ありがとうございました