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
Responsive D3 The React Way
Search
John Bartos
March 16, 2016
Programming
0
210
Responsive D3 The React Way
Use higher-order components to abstract the nastiness of interacting with the real DOM
John Bartos
March 16, 2016
Tweet
Share
Other Decks in Programming
See All in Programming
テストカバレッジ100%を10年続けて得られた学びと品質
mottyzzz
2
610
The Past, Present, and Future of Enterprise Java with ASF in the Middle
ivargrimstad
0
170
Improving my own Ruby thereafter
sisshiki1969
1
160
testingを眺める
matumoto
1
140
JSONataを使ってみよう Step Functionsが楽しくなる実践テクニック #devio2025
dafujii
1
640
Android端末で実現するオンデバイスLLM 2025
masayukisuda
1
170
機能追加とリーダー業務の類似性
rinchoku
2
1.3k
基礎から学ぶ大画面対応(Learning Large-Screen Support from the Ground Up)
tomoya0x00
0
4.3k
実用的なGOCACHEPROG実装をするために / golang.tokyo #40
mazrean
1
290
CJK and Unicode From a PHP Committer
youkidearitai
PRO
0
110
Processing Gem ベースの、2D レトロゲームエンジンの開発
tokujiros
2
130
私の後悔をAWS DMSで解決した話
hiramax
4
210
Featured
See All Featured
How to train your dragon (web standard)
notwaldorf
96
6.2k
Designing Experiences People Love
moore
142
24k
Rails Girls Zürich Keynote
gr2m
95
14k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
53
3k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
113
20k
A better future with KSS
kneath
239
17k
Build your cross-platform service in a week with App Engine
jlugia
231
18k
BBQ
matthewcrist
89
9.8k
Facilitating Awesome Meetings
lara
55
6.5k
Intergalactic Javascript Robots from Outer Space
tanoku
272
27k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
Transcript
Making D3 Responsive The React Way https://johnbartos.github.io/react-d3-demo/ johnbartos.io
I'm John Bartos, and this is my first talk ever
You want to make sweet D3 visualizations that just work™
on all screen sizes (you also care about doing it properly)
But there's a problem...
D3 needs to know its size before runtime You don't
know size until runtime
Fortunately, there's an easy solution
ReactDOM.findDOMNode() GetBoundingClientRect() window.addEventListener('resize', ..) this.setState()
But there are two (2) things wrong with this approach!
findDOMNode() breaks component abstraction
A stateless component is now stateful
You need a higher-order component! (?)
HOCs are functions which take a component and returns another
component that wraps it (thats it)
Our HOC gets size exactly as before and passes it
as props to its child When 'resize' event fires, new props are passed, prompting a rerender
The HOC encapsulates all the nastiness
The wrapped component just gets props
There's a small catch – children render before parents Need
to set initial state in HOC
(Please clap)