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
作ろう、Custom Hooks
Search
surumebeer
October 02, 2019
Programming
1
330
作ろう、Custom Hooks
surumebeer
October 02, 2019
Tweet
Share
More Decks by surumebeer
See All by surumebeer
about ES and TC39
surumebeer
0
270
Other Decks in Programming
See All in Programming
Performance for Conversion! 分散トレーシングでボトルネックを 特定せよ
inetand
0
2.4k
奥深くて厄介な「改行」と仲良くなる20分
oguemon
1
560
テストカバレッジ100%を10年続けて得られた学びと品質
mottyzzz
2
610
私の後悔をAWS DMSで解決した話
hiramax
4
210
CJK and Unicode From a PHP Committer
youkidearitai
PRO
0
110
Deep Dive into Kotlin Flow
jmatsu
1
370
知っているようで知らない"rails new"の世界 / The World of "rails new" You Think You Know but Don't
luccafort
PRO
1
190
はじめてのMaterial3 Expressive
ym223
2
900
Compose Multiplatform × AI で作る、次世代アプリ開発支援ツールの設計と実装
thagikura
0
170
Azure SRE Agentで運用は楽になるのか?
kkamegawa
0
2.5k
Reading Rails 1.0 Source Code
okuramasafumi
0
250
時間軸から考えるTerraformを使う理由と留意点
fufuhu
16
4.8k
Featured
See All Featured
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.4k
How to train your dragon (web standard)
notwaldorf
96
6.2k
Being A Developer After 40
akosma
90
590k
Thoughts on Productivity
jonyablonski
70
4.8k
jQuery: Nuts, Bolts and Bling
dougneiner
64
7.9k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.9k
Context Engineering - Making Every Token Count
addyosmani
3
59
A Modern Web Designer's Workflow
chriscoyier
696
190k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
Typedesign – Prime Four
hannesfritz
42
2.8k
4 Signs Your Business is Dying
shpigford
184
22k
Transcript
作ろう、Custom Hooks 表参道Web勉強会 『Vue.js/PWA/JavaScript…新&定番なんでもあり』 Vol8 @sururmebeer
Shuji Nishino @surumebeer 株式会社 でフロントエンドエンジニアしてます
今日話すこと…
React Hooks
React Hooksとは? • React 16.8から追加されたAPI • 関数型コンポーネントでのみ利用可能 • 関数型コンポーネント自体が状態を持てるようになった •
関数型コンポーネント内で副作用の実行も可能
None
state state更新用の関数 useStateの宣言 stateの初期値
None
useEffectの宣言 副作用 副作用が依存 している関数
stateの操作をCustom Hooks化
None
Hooksを使ってロジック部分を関数として切り離す
Custom Hooksを作って嬉しいこと • ロジック部分を分割して管理ができる • 分割したロジックを、コンポーネントの階層構造に影響することなく共有・再利用できる • プレゼンテーションのコンポーネントは、プレゼンテーションのみに専念させられる
もうちょっと実践的に…
fetchしたjsonを表示する
None
ロジック部分 プレゼンテーション ロジックとUIが同じ関数コンポーネント内にある
Custom Hooksとして切り離す
Hooksを使ってロジック部分だけ関数として切り離す
None
スッキリ!
ご清聴ありがとうございました