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
330
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
作ろう、Custom Hooks
surumebeer
October 02, 2019
More Decks by surumebeer
See All by surumebeer
about ES and TC39
surumebeer
0
280
Other Decks in Programming
See All in Programming
Dockerfile CMD for Node.js
grazie1999
0
110
まだ間に合う!今年の夏こそSchemeのマクロ展開器を完全理解!
omasanori
0
380
異なる設計思想のフレームワークを経験して得た学び
amekuhideki
1
110
「人を評価する AI」の設計と実装
ryoyanara
0
220
改善しないと、タスクが回らない。 “てんこ盛りポジション” を引き継いだ情シスの、入社3ヶ月の業務改善録
krm963
0
280
ドリフトを絶対に許さない(?)CDK運用 / CDK Ops with Zero Tolerance for Drifts (?)
akihisaikeda
1
220
メールのエイリアス機能を履き違えない
isshinfunada
0
250
属人化した知識を、 AIが辿れる地図にする
pkshadeck
PRO
1
200
Building a Meta Ray-Ban display app
akkeylab
0
170
How I Won Prize Money at a Hackathon Using Codex and Symphony Alpha
yasei_no_otoko
0
120
PyConJP2026_wat_Python × Signal Processing: How to Draw Pictures with Sound Using Spectrogram Art
wat
0
160
夏だ!祭りだ!祭りとはドメインモデリングでは?
ryugen04
0
360
Featured
See All Featured
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
390
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
800
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.8k
Producing Creativity
orderedlist
PRO
348
40k
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
540
Art, The Web, and Tiny UX
lynnandtonic
304
22k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
The Cult of Friendly URLs
andyhume
79
7k
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.6k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
500
Everyday Curiosity
cassininazir
0
290
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
1.1k
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
スッキリ!
ご清聴ありがとうございました