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
Introducing React Hooks
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Rizal Ibnu
May 04, 2019
Programming
0
220
Introducing React Hooks
Introducing React Hooks
Rizal Ibnu
May 04, 2019
Tweet
Share
More Decks by Rizal Ibnu
See All by Rizal Ibnu
Bermain dengan React 360
rizalibnu
0
160
Getting Started Remote Working - Kerja Sarungan, Potensi Gaji Karungan
rizalibnu
0
160
Reusable React Component in Kumparan
rizalibnu
0
190
Other Decks in Programming
See All in Programming
Package Management Learnings from Homebrew
mikemcquaid
0
210
CSC307 Lecture 06
javiergs
PRO
0
680
AI によるインシデント初動調査の自動化を行う AI インシデントコマンダーを作った話
azukiazusa1
1
690
AIエージェントのキホンから学ぶ「エージェンティックコーディング」実践入門
masahiro_nishimi
4
310
16年目のピクシブ百科事典を支える最新の技術基盤 / The Modern Tech Stack Powering Pixiv Encyclopedia in its 16th Year
ahuglajbclajep
5
990
Vibe Coding - AI 驅動的軟體開發
mickyp100
0
170
フルサイクルエンジニアリングをAI Agentで全自動化したい 〜構想と現在地〜
kamina_zzz
0
400
Data-Centric Kaggle
isax1015
2
760
OSSとなったswift-buildで Xcodeのビルドを差し替えられるため 自分でXcodeを直せる時代になっている ダイアモンド問題編
yimajo
3
610
CSC307 Lecture 01
javiergs
PRO
0
690
Oxlintはいいぞ
yug1224
5
1.3k
AI & Enginnering
codelynx
0
110
Featured
See All Featured
Facilitating Awesome Meetings
lara
57
6.7k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2k
Speed Design
sergeychernyshev
33
1.5k
Building the Perfect Custom Keyboard
takai
2
680
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
96
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
1
97
Why You Should Never Use an ORM
jnunemaker
PRO
61
9.7k
Music & Morning Musume
bryan
47
7.1k
Designing for Timeless Needs
cassininazir
0
130
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
420
Site-Speed That Sticks
csswizardry
13
1.1k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.3k
Transcript
Introducing React Hooks Rizal Ibnu Software Engineer @kumparan
What, Why & How ?
What, Why & How ?
What are Hooks?
What are Hooks? ?
What are Hooks? ?
What are Hooks? Hooks are a new addition in React
16.8. They let you use state and other React features (such as lifecycle) without writing a class.
What, Why & How ?
Why do we need Hooks?
Why do we use React? • Reusable components • Sensible
data flow • It’s fun to code!
Problems with writing React Class Component? • How to reuse
stateful logic • Huge component • Class is confusing (for both humans and machines)
React Class Component
Might have to reuse this in some other components React
Class Component
React Class Component Split all over the place
How we deal with them? • Mixins (The old way)
• Higher-Order Components a.k.a HOC • Render Props
HOC
HOC
HOC
HOC
HOC Maybe?
HOC
HOC
HOC
HOC
HOC
HOC
HOC WRAPPER HELL
HOC Render Props Hooks Reuse Stateful Logic Explicit Props Composability
No “Wrapper Hell”
Render Props
Render Props
Render Props
Render Props
Render Props
Render Props
Render Props WRAPPER HELL
HOC Render Props Hooks Reuse Stateful Logic Explicit Props Composability
No “Wrapper Hell”
HOC Render Props Hooks Reuse Stateful Logic Explicit Props Composability
No “Wrapper Hell” SPOILER ALERT
What, Why & How ?
HOC Render Props Hooks
Let’s code
HOC Render Props Hooks
Hooks
Hooks
HOC Render Props Hooks Reuse Stateful Logic Explicit Props Composability
No “Wrapper Hell”
But nothing is perfect
Rule of Hooks 1. Only Call Hooks at the Top
Level Don’t call Hooks inside loops, conditions, or nested functions. 2. Only Call Hooks from React Functions Not from regular JS functions or inside class components, but you can call them from custom hooks.
About Hooks • No breaking change • Class still works
• It will cover all use cases for classes! (except getSnapshotBeforeUpdate and componentDidCatch , but they plan to add them soon)
Hooks API Basic Hooks Additional Hooks useState useEffect useContext useReducer
useCallback useMemo useRef useImperativeHandle useLayoutEffect useDebugValue https://reactjs.org/docs/hooks-reference.html
How to try Hooks yarn add react@^16.8.0 yarn add react-dom@^16.8.0
(web) yarn add react-native@^0.59.0 (react native) Recommended yarn add eslint-plugin-react-hooks --dev Code Example https://github.com/rizalibnu/ReactHooksExample (web) https://github.com/rizalibnu/ReactNativeHooksExample (react native)
Reference • https://reactjs.org/docs/hooks-intro.html • https://facebook.github.io/react-native/blog/2019/03/12/releasing-re act-native-059 • https://www.slideshare.net/AikdanaiSidhikosol/react-hooks-101
END GAME