Lock in $30 Savings on PRO—Offer Ends Soon! ⏳
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Introducing React Hooks
Search
Rizal Ibnu
May 04, 2019
Programming
0
210
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
140
Getting Started Remote Working - Kerja Sarungan, Potensi Gaji Karungan
rizalibnu
0
150
Reusable React Component in Kumparan
rizalibnu
0
170
Other Decks in Programming
See All in Programming
関数実行の裏側では何が起きているのか?
minop1205
1
310
アーキテクチャと考える迷子にならない開発者テスト
irof
9
3.4k
Herb to ReActionView: A New Foundation for the View Layer @ San Francisco Ruby Conference 2025
marcoroth
0
210
Building AI Agents with TypeScript #TSKaigiHokuriku
izumin5210
5
1.1k
宅宅自以為的浪漫:跟 AI 一起為自己辦的研討會寫一個售票系統
eddie
0
260
目的で駆動する、AI時代のアーキテクチャ設計 / purpose-driven-architecture
minodriven
11
3.7k
Module Harmony
petamoriken
2
580
なあ兄弟、 余白の意味を考えてから UI実装してくれ!
ktcryomm
10
9.5k
[堅牢.py #1] テストを書かない研究者に送る、最初にテストを書く実験コード入門 / Let's start your ML project by writing tests
shunk031
11
6.3k
AIの弱点、やっぱりプログラミングは人間が(も)勉強しよう / YAPC AI and Programming
kishida
13
5.5k
Microservices Platforms: When Team Topologies Meets Microservices Patterns
cer
PRO
1
720
【レイトレ合宿11】kagayaki_v4
runningoutrate
0
150
Featured
See All Featured
Producing Creativity
orderedlist
PRO
348
40k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
1.8k
The World Runs on Bad Software
bkeepers
PRO
72
12k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.7k
Navigating Team Friction
lara
190
16k
Become a Pro
speakerdeck
PRO
30
5.6k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
54k
Scaling GitHub
holman
464
140k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
36
6.1k
[RailsConf 2023] Rails as a piece of cake
palkan
58
6.1k
Making Projects Easy
brettharned
120
6.5k
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