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
IFSによる形状設計/デモシーンの魅力 @ 慶應大学SFC
gam0022
1
300
AI前提で考えるiOSアプリのモダナイズ設計
yuukiw00w
0
220
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
550
AI Agent Tool のためのバックエンドアーキテクチャを考える #encraft
izumin5210
6
1.8k
そのAIレビュー、レビューしてますか? / Are you reviewing those AI reviews?
rkaga
6
4.5k
Rust 製のコードエディタ “Zed” を使ってみた
nearme_tech
PRO
0
160
humanlayerのブログから学ぶ、良いCLAUDE.mdの書き方
tsukamoto1783
0
190
Fluid Templating in TYPO3 14
s2b
0
130
組織で育むオブザーバビリティ
ryota_hnk
0
170
「ブロックテーマでは再現できない」は本当か?
inc2734
0
960
Spinner 軸ズレ現象を調べたらレンダリング深淵に飲まれた #レバテックMeetup
bengo4com
1
230
MUSUBIXとは
nahisaho
0
130
Featured
See All Featured
[SF Ruby Conf 2025] Rails X
palkan
1
740
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
160
Writing Fast Ruby
sferik
630
62k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
73
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
The Curse of the Amulet
leimatthew05
1
8.4k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
34k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.2k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Raft: Consensus for Rubyists
vanstee
141
7.3k
Between Models and Reality
mayunak
1
180
Technical Leadership for Architectural Decision Making
baasie
1
240
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)