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
List とは何か? / PHPerKaigi 2025
meihei3
0
860
Strategic Design (DDD)for the Frontend @DDD Meetup Stuttgart
manfredsteyer
PRO
0
130
小田原でみんなで一句詠みたいな #phpcon_odawara
stefafafan
0
320
「影響が少ない」を自分の目でみてみる
o0h
PRO
2
1.1k
Do Dumb Things
mitsuhiko
0
430
Unlock the Potential of Swift Code Generation
rockname
0
250
Make Parsers Compatible Using Automata Learning
makenowjust
1
4.5k
Going Structural with Named Tuples
bishabosha
0
200
RubyKaigi Dev Meeting 2025
tenderlove
1
110
大LLM時代にこの先生きのこるには-ITエンジニア編
fumiyakume
7
2.9k
AWS で実現する安全な AI エージェントの作り方 〜 Bedrock Engineer の実装例を添えて 〜 / how-to-build-secure-ai-agents
gawa
8
790
リストビュー画面UX改善の振り返り
splcywolf
0
140
Featured
See All Featured
Art, The Web, and Tiny UX
lynnandtonic
298
20k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
49k
Making Projects Easy
brettharned
116
6.1k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
Optimising Largest Contentful Paint
csswizardry
36
3.2k
The Power of CSS Pseudo Elements
geoffreycrofte
75
5.8k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
32
5.3k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
45
7.2k
YesSQL, Process and Tooling at Scale
rocio
172
14k
Optimizing for Happiness
mojombo
377
70k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.2k
Automating Front-end Workflow
addyosmani
1369
200k
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)