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
快速入門可觀測性
blueswen
0
350
開発者とQAの越境で自動テストが増える開発プロセスを実現する
92thunder
1
180
103 Early Hints
sugi_0000
1
230
DevFest Tokyo 2025 - Flutter のアプリアーキテクチャ現在地点
wasabeef
5
910
フロントエンドのディレクトリ構成どうしてる? Feature-Sliced Design 導入体験談
osakatechlab
8
4.1k
ゆるやかにgolangci-lintのルールを強くする / Kyoto.go #56
utgwkk
2
380
HTTP compression in PHP and Symfony apps
dunglas
2
1.7k
Webエンジニア主体のモバイルチームの 生産性を高く保つためにやったこと
igreenwood
0
330
良いユニットテストを書こう
mototakatsu
7
2.2k
rails stats で紐解く ANDPAD のイマを支える技術たち
andpad
1
290
競技プログラミングへのお誘い@阪大BOOSTセミナー
kotamanegi
0
360
CQRS+ES の力を使って効果を感じる / Feel the effects of using the power of CQRS+ES
seike460
PRO
0
130
Featured
See All Featured
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.9k
GraphQLとの向き合い方2022年版
quramy
44
13k
[RailsConf 2023] Rails as a piece of cake
palkan
53
5k
Embracing the Ebb and Flow
colly
84
4.5k
The Art of Programming - Codeland 2020
erikaheidi
53
13k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
Writing Fast Ruby
sferik
628
61k
Speed Design
sergeychernyshev
25
670
Statistics for Hackers
jakevdp
796
220k
Why Our Code Smells
bkeepers
PRO
335
57k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
5
450
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
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)