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.lazyとSuspenseで行うLazy Load
Search
camcam_lemon
May 27, 2019
Programming
2
380
React.lazyとSuspenseで行うLazy Load
React.js meetup #7 (LT会)での登壇資料です
camcam_lemon
May 27, 2019
Tweet
Share
More Decks by camcam_lemon
See All by camcam_lemon
iOSのキーボード入力ビューをカスタマイズする
lemon
0
72
視え方と文字の大きさ
lemon
1
310
Yarn WorkSpaces × React Nativeの環境構築
lemon
0
220
フロントエンドにおけるアーキテクチャとの向き合い方
lemon
10
4.6k
UI/UXデザイナーがデザインしてるもの
lemon
2
300
react-reduxで追加されたHooks APIの良い所と使い方
lemon
5
880
ESLintで始めるTypeScriptの静的解析
lemon
8
1.9k
SEがエンジニアに目覚めデザイナーに転身した冒険譚
lemon
6
1.4k
なんとなくで書かないReact/ReduxのテストTips
lemon
0
310
Other Decks in Programming
See All in Programming
Ruby Function Composition
bkuhlmann
1
330
Polars入門
daikikatsuragawa
1
100
冗長なエラーログを削減し、スタックトレースを手に入れる / Reducing Verbose Error Logs and Obtaining Stack Traces
upamune
0
790
大規模Reactアプリのリアーキテクチャ~8万行のTanStack Query移行の軌跡~
kj455
4
970
try!Swift Tokyo 2024 参加報告 LT
akidon0000
1
220
Elm 0.19.0 Changes
bkuhlmann
0
490
Code Reviews
bkuhlmann
4
890
Amazon SQSコンシューマー疎結合への旅 - 出張! #DevelopersIO IT技術ブログの中の人が語る勉強会 #3
quiver
0
270
Git Lint
bkuhlmann
4
750
二郎系ラーメンのコールで学ぶ AST 解析
memory1994
PRO
7
1.7k
初心者のためのRubyKaigi入門/RubyKaigi Introduction
a_matsuda
2
850
Fast JSX: Don't clone props object #28768
yossydev
1
130
Featured
See All Featured
10 Git Anti Patterns You Should be Aware of
lemiorhan
648
58k
Making the Leap to Tech Lead
cromwellryan
124
8.5k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
187
16k
Stop Working from a Prison Cell
hatefulcrawdad
266
19k
Typedesign – Prime Four
hannesfritz
36
2.1k
Build your cross-platform service in a week with App Engine
jlugia
225
17k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
19
1.7k
Put a Button on it: Removing Barriers to Going Fast.
kastner
58
3.1k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
20
1.9k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
125
32k
What’s in a name? Adding method to the madness
productmarketing
PRO
16
2.6k
4 Signs Your Business is Dying
shpigford
175
21k
Transcript
React.lazyとSuspenseで行う Lazy Load React.js meetup #7
None
React.lazyとSuspenseって? React 16.6から追加された非同期処理やLazy Load をサポートする機能 Suspense - ・・・dynamic importが完了するまで違う要素 を表示するコンポーネント
React.lazy - ・・・コンポーネントをdynamic importするAPI @loadable/component を使おう SSRには未対応 ただし... なので注意
従来のLazy Load
React.lazyとSusepense を使ってLazy Loadをする
React.lazyとSusepenseを使う
React.lazyとSusepenseを使う コンポーネントの外側で React.lazyでdynamic importする
React.lazyとSusepenseを使う fallback・・・ロード中に表示する要素 children・・・dynamic importする要素
めちゃくちゃ簡潔に書けるぞ!
もっと動的にdynamic import してみよう
やりたいこと 2 React.lazyとSuspenseを使うのは1回 3 ついでにbundleもわけよう 1 propsからimportする要素を決める
None
マウント時に1回だけReact.lazyでコンポーネント を取得するように処理を行う
undefinedにすると無限ループしてしまう depsには空配列を指定(必要であればprops)
webpackChunkNameに [request] を指定すると typeに対応するファイルを別にバンドルする
Formがnullの時があるので三項演算子で判定してから Suspenseを返すようにしている
まとめ 1 custom hooksによる責務の分離 2 可読性の向上 Hooksでより良い体験を propsによる動的かつ汎用的な操作 React.lazyとSuspenseの体験よき
ご静聴ありがとうございました!