Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
React : From Pure function to Hooks
Search
Jongeun Lee
November 23, 2019
Programming
70
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
React : From Pure function to Hooks
Jongeun Lee
November 23, 2019
Other Decks in Programming
See All in Programming
Agents on Rails - Rails at Scale 2026
irinanazarova
0
560
JAWS-UG 東京支部が始める、JAWS-UG支部コラボ / JAWS-UG lunchtime LT Collaboration
y0hgi
0
270
[Dev Group Paris Octobre 26] Agentforce, SIforce, Claudeforce, Slackbot… on s'y retrouve ?
nabondance
0
110
ChromeでローカルLLM
ryu1013
0
140
dotNET_vulnclicker_intro.pdf
deka_morita
0
140
見えないものを探る要求要件定義に必要な基本的思考 / invisible-requirement-thinking
minodriven
15
8.5k
Workers Cache を知る
syumai
0
360
re:Inventに行く前に知っておきたい現地参加のノウハウ
nokomoro3
0
420
気持ちぃ〜角丸 Squircle
ryu1013
0
310
ハーネス設計入門 〜 基礎知識の整理から実務へのステップアップ 〜
kinopeee
28
32k
AIに “答え“を書かせるのを やめてみた
___akari11
0
120
全ての永続トークンを、生まれる前に消し去りたい!
sylph01
2
880
Featured
See All Featured
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
410
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
460
AI Search: Where Are We & What Can We Do About It?
aleyda
0
8.1k
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
480
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
1
750
Joys of Absence: A Defence of Solitary Play
codingconduct
1
550
The #1 spot is gone: here's how to win anyway
tamaranovitovic
4
1.2k
Optimising Largest Contentful Paint
csswizardry
37
4k
How GitHub (no longer) Works
holman
316
150k
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
520
Why Our Code Smells
bkeepers
PRO
340
58k
Writing Fast Ruby
sferik
630
63k
Transcript
Pure function & Hooks Journey from "Pure function" to "Hooks"
1
Jong Jongeun Lee Organizer of JavaScript Developer Forum Korea (jsdev.kr)
Fullstack Developer JavaScript ❤ react-native, redux, terraform, AWS... 2
From to 3
What is Function? 4
Function function add(a, b) { return a + b; }
add(1, 2); Input (arguments) Output (return value) 5
What is Pure Function? 6
Pure Function Same input, same output. NO side effect 7
Why Pure Function? predictable 8
If Same input, same output. NO side effect it is
predictable 9
1. Pure? let c = 0; function add(a, b) {
return a + b + c; } 10
1. Pure? let c = 0; function add(a, b) {
return a + b + c; } add(1, 2); c = 3; add(1, 2); 11
1-1. Pure! function add(a, b, c) { return a +
b + c; } //---------------------------- add(1, 2, 3); add(1, 2, 4); add(1, 2, 3); 12
2. Pure? let globals = { count: 0 }; function
add(a, b) { globals.count++; return a + b; } //---------------------------- add(1, 2); // 3 add(1, 2); // 3 13
2. Pure? let globals = { count: 0 }; function
add(a, b) { globals.count++; return a + b; } //---------------------------- add(1, 2); // 3 globals = undefined; add(1, 2); // ?? 14
2-1. Pure! function add(a, b, count) { return { value:
a + b, count: count + 1 }; } //---------------------------- let myCount = 0; const result = add(1, 2, myCount); myCount = result.count; 15
2-2. Pure! function add(a, b, callback) { callback(); return a
+ b; } //---------------------------- let count = 0; add(1, 2, () => { count++; }); // 3 16
3. Pure? function add(args) { const result = args.left +
args.right; args.left = 0; return result; } add({ left: 1, right: 2 }); 17
If you want to make PURE function Make an output
value using input value. Do NOT change anything existed in outside of function. 18
For React Developer Why understanding pure function is important? 19
React Functional programming Pure function Declarative 20
Evidence 1. Conceptually, components are like JavaScript functions. reactjs.org/docs/components-and-props.html 21
Conceptually, Is this Button a function? <Button title="Press Me" color="green"
onPress={this.onPress} /> Function is " using _____, make ______ " 22
<Button title="Press Me" color="green" onPress={this.onPress} /> input output title, color,
onPress Press Me 23
Evidence 2. All React components must act like pure functions
with respect to their props. reactjs.org/docs/components-and-props.html 24
Pure Function? const MyH1 = ({ title }) => {
return <h1 style={{ color: 'red' }}>{title}</h1>; }; 25
PURE! same props makes same UI <MyH1 title="I love Bali"/>
<MyH1 title="I love Bali"/> I love Bali I love Bali 26
pure function Pros. 1. Test 2. Performance Because it is
predictable. 27
Output? function specialCrazyCalculator(a, b) { return Math.floor(Math.asin((a + b) /
(a + b + 1) / 10) * 123.44566834); } specialCrazyCalculator(1, 2); 28
Speed quiz What is return value? specialCrazyCalculator(1, 2); 29
Test code test('specialCrazyCalculator', () => { expect(specialCrazyCalculator(1, 2)).toBe(9); }); 30
pure function Pros. 1. Test 2. Performance Because it is
predictable. 31
pure function Cons. Can not remember anything by itself In
other words, It doesn't have state. 32
CounterButton Example 33
Which one has to count? 1. CounterButton 2. Parent component
of CounterButton 34
Move count state to CounterButton component 35
Hook 36
We don't know what is useState yet. Try useState 37
Pure or Impure const CounterButton = ({ title }) =>
{ const [count, setCount] = useState(0); return ( <button onClick={() => { setCount(count + 1); }} > {title} : {count} </button> ); }; 38
But conceptually PURE! 39
useState(hook) is another input 40
3. Pure? props , useState are input const CounterButton =
({ title }) => { const [count, setCount] = useState(0); return ( <button onClick={() => { setCount(count + 1); }} > {title} : {count} </button> ); }; 41
Wanna Remember something and Re-render when it changes? const [count,
setCount] = useState(0) [0] : Stored value or initial value. you can NOT change it directly. [1] : A Function that changes the value and triggers re- rendering 42
Wanna make some changes outside of function? useEffect() After rendering,
do something For example setTimeout , setInterval subscribe data fetching imperative API 43
More built-in hooks useContext useReducer useCallback useMemo ... 44
LIVE CODING Custom Hook In other words, Custom Input 45
Summary 46
Pure Function 47
Props and useState are input of Function Component 48
Props : input from Parent Component useState : input from
Hook 49
Terima kasih banyak
[email protected]
50