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
コンポーネントとレンダー
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
nikawa2161
June 17, 2025
17
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
コンポーネントとレンダー
nikawa2161
June 17, 2025
More Decks by nikawa2161
See All by nikawa2161
Node.js Subpath imports
nikawa2161
0
44
Sagaパターン入門(続編)
nikawa2161
0
52
Sagaパターン入門
nikawa2161
0
65
沖縄観光とPostgreSQL排他制約の話
nikawa2161
0
41
20251209_プログラミング原則の学び
nikawa2161
0
41
自分のコードを数年ぶりに読んだら
nikawa2161
0
26
ユーザーインタビュー分析に参加して得られたことと気づき
nikawa2161
0
44
oEmbedとは?
nikawa2161
0
250
はじめまして、にかわです
nikawa2161
0
29
Featured
See All Featured
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
12k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.7k
How to Think Like a Performance Engineer
csswizardry
28
2.9k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
33
5.2k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
250
1.3M
The Limits of Empathy - UXLibs8
cassininazir
2
720
Faster Mobile Websites
deanohume
310
32k
RailsConf 2023
tenderlove
30
1.6k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
520
Mind Mapping
helmedeiros
1
400
Embracing the Ebb and Flow
colly
88
5.2k
Paper Plane
katiecoart
PRO
5
54k
Transcript
関数内の コンポーネントとレンダー
関数内の ・「コンポーネントとして呼び出す」 ・「関数として実行して要素を返す」
1 2 3 4 5 6 7 InnerComponent (() {
<InnerLog name="InnerComponent" />; }, [count]); innerRender (() { <InnerLog name="InnerRender" />; }, [count]); const return const return = => = => useCallback useCallback 1 2 3 4 5 6 7 8 9 10 11 12 13 ( < > < > { } <InnerComponent /> </ > < > { } { ()} </ > </ > ); return div section section section section div /* コンポーネントとして呼び出す */ /* 関数を実行して呼び出す */ innerRender 同じコンポーネント内
1 2 3 4 5 6 7 InnerComponent (() {
<InnerLog name="InnerComponent" />; }, [count]); innerRender (() { <InnerLog name="InnerRender" />; }, [count]); const return const return = => = => useCallback useCallback 1 2 3 4 5 6 7 8 9 10 11 12 13 ( < > < > { } <InnerComponent /> </ > < > { } { ()} </ > </ > ); return div section section section section div /* コンポーネントとして呼び出す */ /* 関数を実行して呼び出す */ innerRender 同じコンポーネント内 1 2 3 4 5 6 InnerLog (({ name } { name }) { (() { . ( ${name} ); }, []); < >{name}</ >; }); const return div div = : : string => => console memo useEffect log ` rendered`
1 2 3 4 5 6 7 8 9 10
11 12 13 ( < > < > { } <InnerComponent /> </ > < > { } { ()} </ > </ > ); return div section section section section div /* コンポーネントとして呼び出す */ /* 関数を実行して呼び出す */ innerRender 状態を更新すると ・<InnerComponent /> は新しいコンポーネントとして解釈 →再レンダリングと再マウントを行う ・innerRender() は要素を返す関数として解釈 →返された要素の再評価は発生せずメモ化された結果を再利用 1 2 3 4 5 6 7 InnerComponent (() { <InnerLog name="InnerComponent" />; }, [count]); innerRender (() { <InnerLog name="InnerRender" />; }, [count]); const return const return = => = => useCallback useCallback
なぜ再レンダリングの挙動が異なるのか?
・レンダリングごとに新しい関数として生成 ・Reactはこの変更を「異なるコンポーネント」と判断 ・古い関数は破棄(アンマウント) InnerComponent innerRender ・ただの関数 ・結果として返されるのはJSX要素 ・メモ化されていれば、再利用される
JSXでの評価の違い InnerComponent 1 <InnerComponent /> 1 React. (InnerComponent, ) createElement
null
JSXでの評価の違い InnerComponent 1 <InnerComponent /> 1 React. (InnerComponent, ) createElement
null innerRender 1 { ()} innerRender 1 React. (InnerLog, { name }) createElement : "InnerRender"